* Support for system-wide distributed / multi-platform builds.

Just set nix.distributedBuilds to true and nix.buildMachines 
  to a list of machines that can perform Nix builds via SSH,
  and local builds will be forwarded appropriately.  So now
  any user can say something like

    nix-build /etc/nixos/nixpkgs/ --arg system '"powerpc-linux"' -A libxml2

  and the build for powerpc-linux will be forwarded to a machine 
  of that type.

svn path=/nixos/trunk/; revision=9696
This commit is contained in:
Eelco Dolstra 2007-11-15 17:16:16 +00:00
parent 14c2bb437d
commit f6fd10cbd8
7 changed files with 90 additions and 16 deletions

View File

@ -1,4 +1,6 @@
{config, pkgs, upstartJobs, systemPath, wrapperDir, defaultShell, extraEtc}: { config, pkgs, upstartJobs, systemPath, wrapperDir
, defaultShell, extraEtc, nixEnvVars
}:
let let
@ -106,6 +108,7 @@ import ../helpers/make-etc.nix {
inherit (pkgs) systemKernel glibc; inherit (pkgs) systemKernel glibc;
timeZone = config.time.timeZone; timeZone = config.time.timeZone;
defaultLocale = config.i18n.defaultLocale; defaultLocale = config.i18n.defaultLocale;
inherit nixEnvVars;
}; };
target = "profile"; target = "profile";
} }
@ -213,6 +216,16 @@ UseSTARTTLS=${if config.networking.defaultMailServer.useSTARTTLS then "YES" else
] ]
) )
# 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";
}
# Additional /etc files declared by Upstart jobs. # Additional /etc files declared by Upstart jobs.
++ extraEtc; ++ extraEtc;

View File

@ -1,6 +1,5 @@
export PATH=@wrapperDir@:/var/run/current-system/sw/bin:/var/run/current-system/sw/sbin export PATH=@wrapperDir@:/var/run/current-system/sw/bin:/var/run/current-system/sw/sbin
export MODULE_DIR=@systemKernel@/lib/modules export MODULE_DIR=@systemKernel@/lib/modules
export NIX_CONF_DIR=/nix/etc/nix
export NIXPKGS_CONFIG=/nix/etc/config.nix export NIXPKGS_CONFIG=/nix/etc/config.nix
export PAGER=less export PAGER=less
export TZ=@timeZone@ export TZ=@timeZone@
@ -27,6 +26,10 @@ else
fi fi
# Set up the environment variables for running Nix.
@nixEnvVars@
# Set up the per-user profile. # Set up the per-user profile.
NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/$USER NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/$USER
mkdir -m 0755 -p $NIX_USER_PROFILE_DIR mkdir -m 0755 -p $NIX_USER_PROFILE_DIR

View File

@ -67,6 +67,8 @@ mkdir -m 0755 -p /var/run/console # for pam_console
touch /var/run/utmp # must exist touch /var/run/utmp # must exist
chmod 644 /var/run/utmp chmod 644 /var/run/utmp
mkdir -m 0755 -p /var/run/nix/current-load # for distributed builds
mkdir -m 0755 -p /var/log mkdir -m 0755 -p /var/log
touch /var/log/wtmp # must exist touch /var/log/wtmp # must exist

View File

@ -1283,6 +1283,52 @@
"; ";
}; };
distributedBuilds = mkOption {
default = false;
description = "
Whether to distribute builds to the machines listed in
<option>nix.buildMachines</option>.
";
};
buildMachines = mkOption {
example = [
{ hostName = "voila.labs.cs.uu.nl";
sshUser = "nix";
sshKey = "/root/.ssh/id_buildfarm";
system = "powerpc-darwin";
maxJobs = 1;
}
{ hostName = "linux64.example.org";
sshUser = "buildfarm";
sshKey = "/root/.ssh/id_buildfarm";
system = "x86_64-linux";
maxJobs = 2;
}
];
description = "
This option lists the machines to be used if distributed
builds are enabled (see
<option>nix.distributedBuilds</option>). Nix will perform
derivations on those machines via SSh by copying the inputs to
the Nix store on the remote machine, starting the build, then
copying the output back to the local Nix store. Each element
of the list should be an attribute set containing the
machine's host name (<varname>hostname</varname>), the user
name to be used for the SSH connection
(<varname>sshUser</varname>), the Nix system type
(<varname>system</varname>, e.g.,
<literal>\"i686-linux\"</literal>), the maximum number of jobs
to be run in parallel on that machine
(<varname>maxJobs</varname>), and the path to the SSH private
key to be used to connect (<varname>sshKey</varname>). The
SSH private key should not have a passphrase, and the
corresponding public key should be added to
<filename>~<replaceable>sshUser<replaceable>/authorized_keys</filename>
on the remote machine.
";
};
}; };

View File

@ -153,24 +153,35 @@ rec {
}; };
# Environment variables for running Nix.
nixEnvVars =
"export NIX_CONF_DIR=/nix/etc/nix\n" +
(if config.nix.distributedBuilds then
"export NIX_BUILD_HOOK=${nix}/libexec/nix/build-remote.pl\n" +
"export NIX_REMOTE_SYSTEMS=/etc/nix.machines\n" +
"export NIX_CURRENT_LOAD=/var/run/nix/current-load\n"
else "");
# The services (Upstart) configuration for the system. # The services (Upstart) configuration for the system.
upstartJobs = import ../upstart-jobs/default.nix { upstartJobs = import ../upstart-jobs/default.nix {
inherit config pkgs nix modprobe nssModulesPath; inherit config pkgs nix modprobe nssModulesPath nixEnvVars;
}; };
# The static parts of /etc. # The static parts of /etc.
etc = import ../etc/default.nix { etc = import ../etc/default.nix {
inherit config pkgs upstartJobs systemPath wrapperDir defaultShell; inherit config pkgs upstartJobs systemPath wrapperDir
defaultShell nixEnvVars;
extraEtc = pkgs.lib.concatLists (map (job: job.extraEtc) upstartJobs.jobs); extraEtc = pkgs.lib.concatLists (map (job: job.extraEtc) upstartJobs.jobs);
}; };
# Font aggregation # Font aggregation
fontDir = import ./fontdir.nix { fontDir = import ./fontdir.nix {
inherit (pkgs) stdenv; inherit (pkgs) stdenv;
inherit pkgs config; inherit pkgs config;
inherit (pkgs.xorg) mkfontdir mkfontscale fontalias; inherit (pkgs.xorg) mkfontdir mkfontscale fontalias;
}; };
# The wrapper setuid programs (since we can't have setuid programs # The wrapper setuid programs (since we can't have setuid programs
# in the Nix store). # in the Nix store).

View File

@ -1,4 +1,4 @@
{config, pkgs, nix, modprobe, nssModulesPath}: {config, pkgs, nix, modprobe, nssModulesPath, nixEnvVars}:
let let
@ -79,8 +79,7 @@ import ../upstart-jobs/gather.nix {
# Nix daemon - required for multi-user Nix. # Nix daemon - required for multi-user Nix.
(import ../upstart-jobs/nix-daemon.nix { (import ../upstart-jobs/nix-daemon.nix {
inherit nix; inherit config pkgs nix nixEnvVars;
inherit (pkgs) openssl;
}) })
# Cron daemon. # Cron daemon.

View File

@ -1,4 +1,4 @@
{nix, openssl}: {config, pkgs, nix, nixEnvVars}:
{ {
name = "nix-daemon"; name = "nix-daemon";
@ -6,11 +6,11 @@
job = " job = "
start on startup start on startup
stop on shutdown stop on shutdown
env NIX_CONF_DIR=/nix/etc/nix
respawn respawn
script script
export PATH=${openssl}/bin:$PATH export PATH=${if config.nix.distributedBuilds then "${pkgs.openssh}/bin:" else ""}${pkgs.openssl}/bin:${nix}/bin:$PATH
exec ${nix}/bin/nix-worker --daemon > /dev/null 2>&1 ${nixEnvVars}
exec ${nix}/bin/nix-worker --daemon > /dev/null 2>&1
end script end script
"; ";