* In the generation of machines.nix, support specifying a

speed factor and multiple system types.

svn path=/nixos/trunk/; revision=17231
This commit is contained in:
Eelco Dolstra 2009-09-17 16:22:26 +00:00
parent bd6fbce0f3
commit 70a10c1720

View File

@ -2,24 +2,27 @@
with pkgs.lib; with pkgs.lib;
###### interface
let let
inherit (config.environment) nix;
in
{
###### interface
options = { options = {
environment = { environment.nix = mkOption {
default = pkgs.nixUnstable;
nix = mkOption { example = pkgs.nixCustomFun /root/nix.tar.gz;
default = pkgs.nixUnstable; merge = mergeOneOption;
example = pkgs.nixCustomFun /root/nix.tar.gz; description = "
merge = mergeOneOption; This option specifies the Nix package instance to use throughout the system.
description = " ";
This option specifies the Nix package instance to use throughout the system.
";
};
}; };
nix = { nix = {
maxJobs = mkOption { maxJobs = mkOption {
@ -119,135 +122,126 @@ let
example = "http://127.0.0.1:3128"; example = "http://127.0.0.1:3128";
}; };
# Environment variables for running Nix. # Environment variables for running Nix. !!! Misnomer - it's
# !!! Fix description. # actually a shell script.
envVars = mkOption { envVars = mkOption {
internal = true; internal = true;
default = ""; default = "";
description = "
Define the environment variables used by nix to
";
merge = pkgs.lib.mergeStringOption; merge = pkgs.lib.mergeStringOption;
description = "
# other option should be used to define the content instead of using Environment variables used by Nix.
# the apply function. ";
apply = conf: ''
export NIX_CONF_DIR=/nix/etc/nix
# Enable the copy-from-other-stores substituter, which allows builds
# to be sped up by copying build results from remote Nix stores. To
# do this, mount the remote file system on a subdirectory of
# /var/run/nix/remote-stores.
export NIX_OTHER_STORES=/var/run/nix/remote-stores/*/nix
'' + # */
(if config.nix.distributedBuilds then
''
export NIX_BUILD_HOOK=${config.environment.nix}/libexec/nix/build-remote.pl
export NIX_REMOTE_SYSTEMS=/etc/nix.machines
export NIX_CURRENT_LOAD=/var/run/nix/current-load
''
else "")
+
(if config.nix.proxy != "" then
''
export http_proxy=${config.nix.proxy}
export https_proxy=${config.nix.proxy}
export ftp_proxy=${config.nix.proxy}
''
else "")
+ conf;
}; };
}; };
}; };
in
###### implementation ###### implementation
let config = {
inherit (config.environment) nix;
in
{ environment.etc =
require = [ [ { # Nix configuration.
options source =
]; let
# Tricky: if we're using a chroot for builds, then we need
environment.etc = # /bin/sh in the chroot (our own compromise to purity).
[ { # Nix configuration. # However, since /bin/sh is a symlink to some path in the
source = # Nix store, which furthermore has runtime dependencies on
let # other paths in the store, we need the closure of /bin/sh
# Tricky: if we're using a chroot for builds, then we need # in `build-chroot-dirs' - otherwise any builder that uses
# /bin/sh in the chroot (our own compromise to purity). # /bin/sh won't work.
# However, since /bin/sh is a symlink to some path in the binshDeps = pkgs.writeReferencesToFile config.system.build.binsh;
# 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;
# Likewise, if chroots are turned on, we need Nix's own # Likewise, if chroots are turned on, we need Nix's own
# closure in the chroot. Otherwise nix-channel and nix-env # closure in the chroot. Otherwise nix-channel and nix-env
# won't work because the dependencies of its builders (like # won't work because the dependencies of its builders (like
# coreutils and Perl) aren't visible. Sigh. # coreutils and Perl) aren't visible. Sigh.
nixDeps = pkgs.writeReferencesToFile config.environment.nix; nixDeps = pkgs.writeReferencesToFile config.environment.nix;
in in
pkgs.runCommand "nix.conf" {extraOptions = config.nix.extraOptions; } '' pkgs.runCommand "nix.conf" {extraOptions = config.nix.extraOptions; } ''
extraPaths=$(for i in $(cat ${binshDeps} ${nixDeps}); do if test -d $i; then echo $i; fi; done) extraPaths=$(for i in $(cat ${binshDeps} ${nixDeps}); do if test -d $i; then echo $i; fi; done)
cat > $out <<END cat > $out <<END
# WARNING: this file is generated. # WARNING: this file is generated.
build-users-group = nixbld build-users-group = nixbld
build-max-jobs = ${toString (config.nix.maxJobs)} build-max-jobs = ${toString (config.nix.maxJobs)}
build-use-chroot = ${if config.nix.useChroot then "true" else "false"} build-use-chroot = ${if config.nix.useChroot then "true" else "false"}
build-chroot-dirs = /dev /dev/pts /proc /bin $(echo $extraPaths) build-chroot-dirs = /dev /dev/pts /proc /bin $(echo $extraPaths)
$extraOptions $extraOptions
END END
''; '';
target = "nix.conf"; # will be symlinked from /nix/etc/nix/nix.conf in activate-configuration.sh. target = "nix.conf"; # will be symlinked from /nix/etc/nix/nix.conf in activate-configuration.sh.
} }
] ]
++ optional config.nix.distributedBuilds ++ optional config.nix.distributedBuilds
{ # List of machines for distributed Nix builds in the format expected { # List of machines for distributed Nix builds in the format expected
# by build-remote.pl. # by build-remote.pl.
source = pkgs.writeText "nix.machines" source = pkgs.writeText "nix.machines"
(pkgs.lib.concatStrings (map (machine: (pkgs.lib.concatStrings (map (machine:
"${machine.sshUser}@${machine.hostName} ${machine.system} ${machine.sshKey} ${toString machine.maxJobs}\n" "${machine.sshUser}@${machine.hostName} "
) config.nix.buildMachines)); + (if machine ? system then machine.system else concatStringsSep "," machine.systems)
target = "nix.machines"; + " ${machine.sshKey} ${toString machine.maxJobs} "
+ (if machine ? speedFactor then toString machine.speedFactor else "1" )
+ "\n"
) config.nix.buildMachines));
target = "nix.machines";
};
jobs = pkgs.lib.singleton
{ name = "nix-daemon";
startOn = "startup";
script =
''
export PATH=${if config.nix.distributedBuilds then "${pkgs.openssh}/bin:${pkgs.gzip}/bin:" else ""}${pkgs.openssl}/bin:${nix}/bin:$PATH
${config.nix.envVars}
exec nice -n ${builtins.toString config.nix.daemonNiceLevel} ${nix}/bin/nix-worker --daemon > /dev/null 2>&1
'';
extraConfig =
''
limit nofile 4096 4096
'';
}; };
jobs = pkgs.lib.singleton environment.shellInit =
{ name = "nix-daemon"; ''
# Set up the environment variables for running Nix.
startOn = "startup"; ${config.nix.envVars}
script =
''
export PATH=${if config.nix.distributedBuilds then "${pkgs.openssh}/bin:${pkgs.gzip}/bin:" else ""}${pkgs.openssl}/bin:${nix}/bin:$PATH
${config.nix.envVars}
exec nice -n ${builtins.toString config.nix.daemonNiceLevel} ${nix}/bin/nix-worker --daemon > /dev/null 2>&1
'';
extraConfig =
''
limit nofile 4096 4096
'';
};
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 # Set up secure multi-user builds: non-root users build through the
# Nix daemon. # Nix daemon.
if test "$USER" != root; then if test "$USER" != root; then
export NIX_REMOTE=daemon export NIX_REMOTE=daemon
else else
export NIX_REMOTE= export NIX_REMOTE=
fi fi
''; '';
nix.envVars =
''
export NIX_CONF_DIR=/nix/etc/nix
# Enable the copy-from-other-stores substituter, which allows builds
# to be sped up by copying build results from remote Nix stores. To
# do this, mount the remote file system on a subdirectory of
# /var/run/nix/remote-stores.
export NIX_OTHER_STORES=/var/run/nix/remote-stores/*/nix
''
+ optionalString config.nix.distributedBuilds ''
export NIX_BUILD_HOOK=${config.environment.nix}/libexec/nix/build-remote.pl
export NIX_REMOTE_SYSTEMS=/etc/nix.machines
export NIX_CURRENT_LOAD=/var/run/nix/current-load
''
# !!! These should not be defined here, but in some general proxy configuration module!
+ optionalString (config.nix.proxy != "") ''
export http_proxy=${config.nix.proxy}
export https_proxy=${config.nix.proxy}
export ftp_proxy=${config.nix.proxy}
'';
};
} }