diff --git a/etc/default.nix b/etc/default.nix index 42037c8d440d..cbcb094a0528 100644 --- a/etc/default.nix +++ b/etc/default.nix @@ -88,19 +88,8 @@ let "common" "common-console" # shared stuff for interactive local sessions ] - ) + ); - # List of machines for distributed Nix builds in the format expected - # by build-remote.pl. - ++ optional config.nix.distributedBuilds { - source = pkgs.writeText "nix.machines" - (pkgs.lib.concatStrings (map (machine: - "${machine.sshUser}@${machine.hostName} ${machine.system} ${machine.sshKey} ${toString machine.maxJobs}\n" - ) config.nix.buildMachines)); - target = "nix.machines"; - } - - ; in let diff --git a/modules/programs/bash/bash.nix b/modules/programs/bash/bash.nix index e7be3b5e1029..d992d0888bae 100644 --- a/modules/programs/bash/bash.nix +++ b/modules/programs/bash/bash.nix @@ -15,7 +15,6 @@ wrapperDir = config.security.wrapperDir; modulesTree = config.system.modulesTree; defaultLocale = config.i18n.defaultLocale; - nixEnvVars = config.nix.envVars; shellInit = config.environment.shellInit; }; target = "bashrc"; diff --git a/modules/programs/bash/bashrc.sh b/modules/programs/bash/bashrc.sh index ad6e5d3f2477..d18cb010b507 100644 --- a/modules/programs/bash/bashrc.sh +++ b/modules/programs/bash/bashrc.sh @@ -9,21 +9,8 @@ export LANG=@defaultLocale@ export EDITOR=nano export INFOPATH=/var/run/current-system/sw/info:/var/run/current-system/sw/share/info export LOCATE_PATH=/var/cache/locatedb -@shellInit@ export LOCALE_ARCHIVE=/var/run/current-system/sw/lib/locale/locale-archive - - -# Set up secure multi-user builds: non-root users build through the -# Nix daemon. -if test "$USER" != root; then - export NIX_REMOTE=daemon -else - export NIX_REMOTE= -fi - - -# Set up the environment variables for running Nix. -@nixEnvVars@ +@shellInit@ # Include the various profiles in the appropriate environment variables. diff --git a/modules/services/misc/nix-daemon.nix b/modules/services/misc/nix-daemon.nix index 544ddab58326..ee8d67f74713 100644 --- a/modules/services/misc/nix-daemon.nix +++ b/modules/services/misc/nix-daemon.nix @@ -178,13 +178,12 @@ let }; }; }; + in ###### implementation let - binsh = config.system.build.binsh; - nixEnvVars = config.nix.envVars; inherit (config.environment) nix; in @@ -193,9 +192,8 @@ in options ]; - environment = { - etc = [ - { # Nix configuration. + environment.etc = + [ { # Nix configuration. source = let # Tricky: if we're using a chroot for builds, then we need @@ -205,7 +203,7 @@ in # other paths in the store, we need the closure of /bin/sh # in `build-chroot-dirs' - otherwise any builder that uses # /bin/sh won't work. - binshDeps = pkgs.writeReferencesToFile binsh; + binshDeps = pkgs.writeReferencesToFile config.system.build.binsh; # Likewise, if chroots are turned on, we need Nix's own # closure in the chroot. Otherwise nix-channel and nix-env @@ -226,23 +224,45 @@ in ''; target = "nix.conf"; # will be symlinked from /nix/etc/nix/nix.conf in activate-configuration.sh. } - ]; - }; + ] + + ++ optional config.nix.distributedBuilds + { # List of machines for distributed Nix builds in the format expected + # by build-remote.pl. + source = pkgs.writeText "nix.machines" + (pkgs.lib.concatStrings (map (machine: + "${machine.sshUser}@${machine.hostName} ${machine.system} ${machine.sshKey} ${toString machine.maxJobs}\n" + ) config.nix.buildMachines)); + target = "nix.machines"; + }; + + services.extraJobs = [ + { name = "nix-daemon"; - services = { - extraJobs = [{ - name = "nix-daemon"; - job = '' start on startup stop on shutdown respawn script export PATH=${if config.nix.distributedBuilds then "${pkgs.openssh}/bin:" else ""}${pkgs.openssl}/bin:${nix}/bin:$PATH - ${nixEnvVars} + ${config.nix.envVars} exec ${nix}/bin/nix-worker --daemon > /dev/null 2>&1 end script ''; - }]; - }; + } + ]; + + environment.shellInit = + '' + # Set up the environment variables for running Nix. + ${config.nix.envVars} + + # Set up secure multi-user builds: non-root users build through the + # Nix daemon. + if test "$USER" != root; then + export NIX_REMOTE=daemon + else + export NIX_REMOTE= + fi + ''; }