diff --git a/config.nix b/config.nix index 1cccbb7..9d91476 100644 --- a/config.nix +++ b/config.nix @@ -14,6 +14,7 @@ let ./modules/system/launchd.nix ./modules/environment ./modules/launchd + ./modules/services/activate-system.nix ./modules/programs/tmux.nix ]; }; @@ -36,10 +37,7 @@ let pkgs.nox ]; - launchd.daemons.activate-system = - { serviceConfig.Program = "${config.system.build.activate}"; - serviceConfig.RunAtLoad = true; - }; + services.activate-system.enable = true; launchd.daemons.nix-daemon = { serviceConfig.Program = "/nix/var/nix/profiles/default/bin/nix-daemon"; @@ -121,7 +119,7 @@ let 'build') nix-build '' -A nixdarwin.toplevel "$@" ;; 'repl') nix-repl "$HOME/.nixpkgs/config.nix" "$@" ;; 'shell') nix-shell '' -p nixdarwin.toplevel --run '${pkgs.lnl.zsh}/bin/zsh -l' "$@" ;; - 'switch') sudo nix-env --profile /nix/var/nix/profiles/system --set $(nix-build --no-out-link '' -A nixdarwin.toplevel) && nix-shell '' -A nixdarwin.toplevel --run 'sudo $out/activate' && exec ${pkgs.lnl.zsh}/bin/zsh -l ;; + 'switch') sudo nix-env --profile ${config.system.profile} --set $(nix-build --no-out-link '' -A nixdarwin.toplevel) && nix-shell '' -A nixdarwin.toplevel --run 'sudo $out/activate' && exec ${pkgs.lnl.zsh}/bin/zsh -l ;; esac } diff --git a/modules/services/activate-system.nix b/modules/services/activate-system.nix new file mode 100644 index 0000000..a92576f --- /dev/null +++ b/modules/services/activate-system.nix @@ -0,0 +1,47 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.activate-system; + + activateScript = pkgs.writeScript "activate-system" '' + #! ${pkgs.stdenv.shell} + + # Make this configuration the current configuration. + # The readlink is there to ensure that when $systemConfig = /system + # (which is a symlink to the store), /run/current-system is still + # used as a garbage collection root. + ln -sfn $(cat ${config.system.profile}/systemConfig) /run/current-system + + # Prevent the current configuration from being garbage-collected. + ln -sfn /run/current-system /nix/var/nix/gcroots/current-system + ''; + +in + +{ + options = { + services.activate-system = { + + enable = mkOption { + type = types.bool; + default = false; + description = '' + Whether to activate system at boot time. + ''; + }; + + }; + }; + + config = { + + launchd.daemons.activate-system = mkIf cfg.enable { + serviceConfig.Program = "${activateScript}"; + serviceConfig.RunAtLoad = true; + }; + + }; +} diff --git a/modules/system/activation-scripts.nix b/modules/system/activation-scripts.nix index fe3131d..fda882f 100644 --- a/modules/system/activation-scripts.nix +++ b/modules/system/activation-scripts.nix @@ -34,19 +34,6 @@ in config = { - system.build.activate = pkgs.writeScript "activate-system" '' - #! ${pkgs.stdenv.shell} - - # Make this configuration the current configuration. - # The readlink is there to ensure that when $systemConfig = /system - # (which is a symlink to the store), /run/current-system is still - # used as a garbage collection root. - ln -sfn $(cat /nix/var/nix/profiles/system/systemConfig) /run/current-system - - # Prevent the current configuration from being garbage-collected. - ln -sfn /run/current-system /nix/var/nix/gcroots/current-system - ''; - system.activationScripts.script.text = '' #! ${pkgs.stdenv.shell} diff --git a/modules/system/default.nix b/modules/system/default.nix index 9cf190e..d1d9f72 100644 --- a/modules/system/default.nix +++ b/modules/system/default.nix @@ -27,6 +27,14 @@ in ''; }; + system.profile = mkOption { + type = types.path; + default = "/nix/var/nix/profiles/system"; + description = '' + Profile to use for the system. + ''; + }; + system.nixdarwinLabel = mkOption { type = types.str; default = "16.09";