nix-daemon: Restart when nix.conf changes

This commit is contained in:
Eelco Dolstra 2013-02-26 03:15:29 +01:00
parent cc3549fa34
commit 85188d19c5

View File

@ -20,6 +20,31 @@ let
extraGroups = [ "nixbld" ]; extraGroups = [ "nixbld" ];
}; };
nixConf =
let
# Tricky: if we're using a chroot for builds, then we need
# /bin/sh in the chroot (our own compromise to purity).
# However, since /bin/sh is a symlink to some path in the
# Nix store, which furthermore has runtime dependencies on
# 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 config.system.build.binsh;
in
pkgs.runCommand "nix.conf" {extraOptions = cfg.extraOptions; } ''
extraPaths=$(for i in $(cat ${binshDeps}); do if test -d $i; then echo $i; fi; done)
cat > $out <<END
# WARNING: this file is generated.
build-users-group = nixbld
build-max-jobs = ${toString (cfg.maxJobs)}
build-use-chroot = ${if cfg.useChroot then "true" else "false"}
build-chroot-dirs = ${toString cfg.chrootDirs} $(echo $extraPaths)
binary-caches = ${toString cfg.binaryCaches}
trusted-binary-caches = ${toString cfg.trustedBinaryCaches}
$extraOptions
END
'';
in in
{ {
@ -226,48 +251,20 @@ in
nix.chrootDirs = [ "/dev" "/dev/pts" "/proc" "/bin" ]; nix.chrootDirs = [ "/dev" "/dev/pts" "/proc" "/bin" ];
environment.etc = environment.etc."nix/nix.conf".source = nixConf;
[ { # Nix configuration.
source =
let
# Tricky: if we're using a chroot for builds, then we need
# /bin/sh in the chroot (our own compromise to purity).
# However, since /bin/sh is a symlink to some path in the
# Nix store, which furthermore has runtime dependencies on
# 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 config.system.build.binsh;
in
pkgs.runCommand "nix.conf" {extraOptions = cfg.extraOptions; } ''
extraPaths=$(for i in $(cat ${binshDeps}); do if test -d $i; then echo $i; fi; done)
cat > $out <<END
# WARNING: this file is generated.
build-users-group = nixbld
build-max-jobs = ${toString (cfg.maxJobs)}
build-use-chroot = ${if cfg.useChroot then "true" else "false"}
build-chroot-dirs = ${toString cfg.chrootDirs} $(echo $extraPaths)
binary-caches = ${toString cfg.binaryCaches}
trusted-binary-caches = ${toString cfg.trustedBinaryCaches}
$extraOptions
END
'';
target = "nix/nix.conf";
}
]
++ optional (cfg.distributedBuilds && !cfg.manualNixMachines) # List of machines for distributed Nix builds in the format
{ # List of machines for distributed Nix builds in the format expected # expected by build-remote.pl.
# by build-remote.pl. environment.etc."nix.machines" =
source = pkgs.writeText "nix.machines" { enable = cfg.distributedBuilds && !cfg.manualNixMachines;
(concatStrings (map (machine: text =
concatMapStrings (machine:
"${machine.sshUser}@${machine.hostName} " "${machine.sshUser}@${machine.hostName} "
+ (if machine ? system then machine.system else concatStringsSep "," machine.systems) + (if machine ? system then machine.system else concatStringsSep "," machine.systems)
+ " ${machine.sshKey} ${toString machine.maxJobs} " + " ${machine.sshKey} ${toString machine.maxJobs} "
+ (if machine ? speedFactor then toString machine.speedFactor else "1" ) + (if machine ? speedFactor then toString machine.speedFactor else "1" )
+ "\n" + "\n"
) cfg.buildMachines)); ) cfg.buildMachines;
target = "nix.machines";
}; };
systemd.sockets."nix-daemon" = systemd.sockets."nix-daemon" =
@ -292,6 +289,8 @@ in
IOSchedulingPriority = cfg.daemonIONiceLevel; IOSchedulingPriority = cfg.daemonIONiceLevel;
LimitNOFILE = 4096; LimitNOFILE = 4096;
}; };
restartTriggers = [ nixConf ];
}; };
nix.envVars = nix.envVars =