diff options
| -rw-r--r-- | modules/nix/default.nix | 25 | ||||
| -rw-r--r-- | modules/services/nix-daemon.nix | 10 | ||||
| -rw-r--r-- | modules/system/activation-scripts.nix | 1 |
3 files changed, 28 insertions, 8 deletions
diff --git a/modules/nix/default.nix b/modules/nix/default.nix index c826713..9381a7c 100644 --- a/modules/nix/default.nix +++ b/modules/nix/default.nix @@ -54,6 +54,16 @@ in ''; }; + nix.useDaemon = mkOption { + type = types.bool; + default = false; + description = " + If set, Nix will use the daemon to perform operations. + Use this instead of services.nix-daemon.enable if you don't wan't the + daemon service to be managed for you. + "; + }; + nix.maxJobs = mkOption { type = types.int; default = 1; @@ -346,6 +356,14 @@ in NIX_CURRENT_LOAD = "/run/nix/current-load"; }; + environment.extraInit = mkIf cfg.useDaemon '' + # Set up secure multi-user builds: non-root users build through the + # Nix daemon. + if [ "$USER" != root -o ! -w /nix/var/nix/db ]; then + export NIX_REMOTE=daemon + fi + ''; + # Set up the environment variables for running Nix. environment.variables = cfg.envVars // { NIX_PATH = concatStringsSep ":" cfg.nixPath; @@ -357,5 +375,12 @@ in fi ''; + system.activationScripts.nix-daemon.text = mkIf cfg.useDaemon '' + if ! diff /etc/nix/nix.conf /run/current-system/etc/nix/nix.conf &> /dev/null; then + echo "reloading nix-daemon..." >&2 + pkill -HUP nix-daemon + fi + ''; + }; } diff --git a/modules/services/nix-daemon.nix b/modules/services/nix-daemon.nix index f29d8a9..92cf422 100644 --- a/modules/services/nix-daemon.nix +++ b/modules/services/nix-daemon.nix @@ -11,7 +11,7 @@ in services.nix-daemon.enable = mkOption { type = types.bool; default = false; - description = "Whether to activate system at boot time."; + description = "Whether to enable the nix-daemon service."; }; services.nix-daemon.logFile = mkOption { @@ -35,13 +35,7 @@ in config = mkIf cfg.enable { - environment.extraInit = '' - # Set up secure multi-user builds: non-root users build through the - # Nix daemon. - if [ "$USER" != root -o ! -w /nix/var/nix/db ]; then - export NIX_REMOTE=daemon - fi - ''; + nix.useDaemon = true; launchd.daemons.nix-daemon = { command = "${config.nix.package}/bin/nix-daemon"; diff --git a/modules/system/activation-scripts.nix b/modules/system/activation-scripts.nix index c1b506c..dcf4762 100644 --- a/modules/system/activation-scripts.nix +++ b/modules/system/activation-scripts.nix @@ -56,6 +56,7 @@ in ${cfg.activationScripts.applications.text} ${cfg.activationScripts.etc.text} ${cfg.activationScripts.launchd.text} + ${cfg.activationScripts.nix-daemon.text} ${cfg.activationScripts.time.text} ${cfg.activationScripts.networking.text} |
