* 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:
parent
bd6fbce0f3
commit
70a10c1720
@ -2,22 +2,25 @@
|
|||||||
|
|
||||||
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 = {
|
||||||
@ -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
|
||||||
|
# /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;
|
||||||
|
|
||||||
environment.etc =
|
# Likewise, if chroots are turned on, we need Nix's own
|
||||||
[ { # Nix configuration.
|
# closure in the chroot. Otherwise nix-channel and nix-env
|
||||||
source =
|
# won't work because the dependencies of its builders (like
|
||||||
let
|
# coreutils and Perl) aren't visible. Sigh.
|
||||||
# Tricky: if we're using a chroot for builds, then we need
|
nixDeps = pkgs.writeReferencesToFile config.environment.nix;
|
||||||
# /bin/sh in the chroot (our own compromise to purity).
|
in
|
||||||
# However, since /bin/sh is a symlink to some path in the
|
pkgs.runCommand "nix.conf" {extraOptions = config.nix.extraOptions; } ''
|
||||||
# Nix store, which furthermore has runtime dependencies on
|
extraPaths=$(for i in $(cat ${binshDeps} ${nixDeps}); do if test -d $i; then echo $i; fi; done)
|
||||||
# other paths in the store, we need the closure of /bin/sh
|
cat > $out <<END
|
||||||
# in `build-chroot-dirs' - otherwise any builder that uses
|
# WARNING: this file is generated.
|
||||||
# /bin/sh won't work.
|
build-users-group = nixbld
|
||||||
binshDeps = pkgs.writeReferencesToFile config.system.build.binsh;
|
build-max-jobs = ${toString (config.nix.maxJobs)}
|
||||||
|
build-use-chroot = ${if config.nix.useChroot then "true" else "false"}
|
||||||
|
build-chroot-dirs = /dev /dev/pts /proc /bin $(echo $extraPaths)
|
||||||
|
$extraOptions
|
||||||
|
END
|
||||||
|
'';
|
||||||
|
target = "nix.conf"; # will be symlinked from /nix/etc/nix/nix.conf in activate-configuration.sh.
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
# Likewise, if chroots are turned on, we need Nix's own
|
++ optional config.nix.distributedBuilds
|
||||||
# closure in the chroot. Otherwise nix-channel and nix-env
|
{ # List of machines for distributed Nix builds in the format expected
|
||||||
# won't work because the dependencies of its builders (like
|
# by build-remote.pl.
|
||||||
# coreutils and Perl) aren't visible. Sigh.
|
source = pkgs.writeText "nix.machines"
|
||||||
nixDeps = pkgs.writeReferencesToFile config.environment.nix;
|
(pkgs.lib.concatStrings (map (machine:
|
||||||
in
|
"${machine.sshUser}@${machine.hostName} "
|
||||||
pkgs.runCommand "nix.conf" {extraOptions = config.nix.extraOptions; } ''
|
+ (if machine ? system then machine.system else concatStringsSep "," machine.systems)
|
||||||
extraPaths=$(for i in $(cat ${binshDeps} ${nixDeps}); do if test -d $i; then echo $i; fi; done)
|
+ " ${machine.sshKey} ${toString machine.maxJobs} "
|
||||||
cat > $out <<END
|
+ (if machine ? speedFactor then toString machine.speedFactor else "1" )
|
||||||
# WARNING: this file is generated.
|
+ "\n"
|
||||||
build-users-group = nixbld
|
) config.nix.buildMachines));
|
||||||
build-max-jobs = ${toString (config.nix.maxJobs)}
|
target = "nix.machines";
|
||||||
build-use-chroot = ${if config.nix.useChroot then "true" else "false"}
|
};
|
||||||
build-chroot-dirs = /dev /dev/pts /proc /bin $(echo $extraPaths)
|
|
||||||
$extraOptions
|
|
||||||
END
|
|
||||||
'';
|
|
||||||
target = "nix.conf"; # will be symlinked from /nix/etc/nix/nix.conf in activate-configuration.sh.
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
++ optional config.nix.distributedBuilds
|
jobs = pkgs.lib.singleton
|
||||||
{ # List of machines for distributed Nix builds in the format expected
|
{ name = "nix-daemon";
|
||||||
# by build-remote.pl.
|
|
||||||
source = pkgs.writeText "nix.machines"
|
startOn = "startup";
|
||||||
(pkgs.lib.concatStrings (map (machine:
|
|
||||||
"${machine.sshUser}@${machine.hostName} ${machine.system} ${machine.sshKey} ${toString machine.maxJobs}\n"
|
script =
|
||||||
) config.nix.buildMachines));
|
''
|
||||||
target = "nix.machines";
|
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.
|
||||||
|
${config.nix.envVars}
|
||||||
|
|
||||||
startOn = "startup";
|
# 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
|
||||||
|
'';
|
||||||
|
|
||||||
script =
|
nix.envVars =
|
||||||
''
|
''
|
||||||
export PATH=${if config.nix.distributedBuilds then "${pkgs.openssh}/bin:${pkgs.gzip}/bin:" else ""}${pkgs.openssl}/bin:${nix}/bin:$PATH
|
export NIX_CONF_DIR=/nix/etc/nix
|
||||||
${config.nix.envVars}
|
|
||||||
exec nice -n ${builtins.toString config.nix.daemonNiceLevel} ${nix}/bin/nix-worker --daemon > /dev/null 2>&1
|
|
||||||
'';
|
|
||||||
|
|
||||||
extraConfig =
|
# Enable the copy-from-other-stores substituter, which allows builds
|
||||||
''
|
# to be sped up by copying build results from remote Nix stores. To
|
||||||
limit nofile 4096 4096
|
# 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}
|
||||||
|
'';
|
||||||
|
|
||||||
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
|
|
||||||
'';
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user