diff --git a/etc/default.nix b/etc/default.nix
index 01b79872efe..5d230ff893b 100644
--- a/etc/default.nix
+++ b/etc/default.nix
@@ -1,4 +1,6 @@
-{config, pkgs, upstartJobs, systemPath, wrapperDir, defaultShell, extraEtc}:
+{ config, pkgs, upstartJobs, systemPath, wrapperDir
+, defaultShell, extraEtc, nixEnvVars
+}:
let
@@ -106,6 +108,7 @@ import ../helpers/make-etc.nix {
inherit (pkgs) systemKernel glibc;
timeZone = config.time.timeZone;
defaultLocale = config.i18n.defaultLocale;
+ inherit nixEnvVars;
};
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.
++ extraEtc;
diff --git a/etc/profile.sh b/etc/profile.sh
index cb915a7f7c4..992f23afaba 100644
--- a/etc/profile.sh
+++ b/etc/profile.sh
@@ -1,6 +1,5 @@
export PATH=@wrapperDir@:/var/run/current-system/sw/bin:/var/run/current-system/sw/sbin
export MODULE_DIR=@systemKernel@/lib/modules
-export NIX_CONF_DIR=/nix/etc/nix
export NIXPKGS_CONFIG=/nix/etc/config.nix
export PAGER=less
export TZ=@timeZone@
@@ -27,6 +26,10 @@ else
fi
+# Set up the environment variables for running Nix.
+@nixEnvVars@
+
+
# Set up the per-user profile.
NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/$USER
mkdir -m 0755 -p $NIX_USER_PROFILE_DIR
diff --git a/system/activate-configuration.sh b/system/activate-configuration.sh
index 3767fc91d49..962be60b2a3 100644
--- a/system/activate-configuration.sh
+++ b/system/activate-configuration.sh
@@ -67,6 +67,8 @@ mkdir -m 0755 -p /var/run/console # for pam_console
touch /var/run/utmp # must exist
chmod 644 /var/run/utmp
+mkdir -m 0755 -p /var/run/nix/current-load # for distributed builds
+
mkdir -m 0755 -p /var/log
touch /var/log/wtmp # must exist
diff --git a/system/options.nix b/system/options.nix
index 2aa64fedd8c..6d5a0c967a0 100644
--- a/system/options.nix
+++ b/system/options.nix
@@ -1283,6 +1283,52 @@
";
};
+ distributedBuilds = mkOption {
+ default = false;
+ description = "
+ Whether to distribute builds to the machines listed in
+ .
+ ";
+ };
+
+ 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
+ ). 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 (hostname), the user
+ name to be used for the SSH connection
+ (sshUser), the Nix system type
+ (system, e.g.,
+ \"i686-linux\"), the maximum number of jobs
+ to be run in parallel on that machine
+ (maxJobs), and the path to the SSH private
+ key to be used to connect (sshKey). The
+ SSH private key should not have a passphrase, and the
+ corresponding public key should be added to
+ ~sshUser/authorized_keys
+ on the remote machine.
+ ";
+ };
+
};
diff --git a/system/system.nix b/system/system.nix
index 2745388e0d4..b07636e7347 100644
--- a/system/system.nix
+++ b/system/system.nix
@@ -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.
upstartJobs = import ../upstart-jobs/default.nix {
- inherit config pkgs nix modprobe nssModulesPath;
+ inherit config pkgs nix modprobe nssModulesPath nixEnvVars;
};
# The static parts of /etc.
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);
};
# Font aggregation
- fontDir = import ./fontdir.nix {
- inherit (pkgs) stdenv;
- inherit pkgs config;
- inherit (pkgs.xorg) mkfontdir mkfontscale fontalias;
- };
+ fontDir = import ./fontdir.nix {
+ inherit (pkgs) stdenv;
+ inherit pkgs config;
+ inherit (pkgs.xorg) mkfontdir mkfontscale fontalias;
+ };
# The wrapper setuid programs (since we can't have setuid programs
# in the Nix store).
diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix
index 040119ecc73..42fc4c0b7d4 100644
--- a/upstart-jobs/default.nix
+++ b/upstart-jobs/default.nix
@@ -1,4 +1,4 @@
-{config, pkgs, nix, modprobe, nssModulesPath}:
+{config, pkgs, nix, modprobe, nssModulesPath, nixEnvVars}:
let
@@ -79,8 +79,7 @@ import ../upstart-jobs/gather.nix {
# Nix daemon - required for multi-user Nix.
(import ../upstart-jobs/nix-daemon.nix {
- inherit nix;
- inherit (pkgs) openssl;
+ inherit config pkgs nix nixEnvVars;
})
# Cron daemon.
diff --git a/upstart-jobs/nix-daemon.nix b/upstart-jobs/nix-daemon.nix
index acf85c70c9c..553c1c93533 100644
--- a/upstart-jobs/nix-daemon.nix
+++ b/upstart-jobs/nix-daemon.nix
@@ -1,4 +1,4 @@
-{nix, openssl}:
+{config, pkgs, nix, nixEnvVars}:
{
name = "nix-daemon";
@@ -6,11 +6,11 @@
job = "
start on startup
stop on shutdown
- env NIX_CONF_DIR=/nix/etc/nix
respawn
script
- export PATH=${openssl}/bin:$PATH
- exec ${nix}/bin/nix-worker --daemon > /dev/null 2>&1
+ export PATH=${if config.nix.distributedBuilds then "${pkgs.openssh}/bin:" else ""}${pkgs.openssl}/bin:${nix}/bin:$PATH
+ ${nixEnvVars}
+ exec ${nix}/bin/nix-worker --daemon > /dev/null 2>&1
end script
";