diff --git a/modules/system/activation/top-level.nix b/modules/system/activation/top-level.nix index 262a3bb9ae7..cb3c4e8941d 100644 --- a/modules/system/activation/top-level.nix +++ b/modules/system/activation/top-level.nix @@ -99,8 +99,7 @@ let let kernelPath = "${config.boot.kernelPackages.kernel}/" + "${config.system.boot.loader.kernelFile}"; - in - '' + in '' ensureDir $out if [ ! -f ${kernelPath} ]; then diff --git a/modules/system/boot/stage-1.nix b/modules/system/boot/stage-1.nix index 9a324124a9d..7f8287e7e4b 100644 --- a/modules/system/boot/stage-1.nix +++ b/modules/system/boot/stage-1.nix @@ -329,5 +329,6 @@ in { system.build.bootStage1 = bootStage1; system.build.initialRamdisk = initialRamdisk; + system.build.extraUtils = extraUtils; } diff --git a/tests/default.nix b/tests/default.nix index 015eb071a15..e99bce510ec 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -17,6 +17,7 @@ with import ../lib/testing.nix { inherit nixpkgs services system; }; portmap = makeTest (import ./portmap.nix); proxy = makeTest (import ./proxy.nix); quake3 = makeTest (import ./quake3.nix); + remote_builds = makeTest (import ./remote-builds.nix); subversion = makeTest (import ./subversion.nix); trac = makeTest (import ./trac.nix); } diff --git a/tests/remote-builds.nix b/tests/remote-builds.nix new file mode 100644 index 00000000000..b567c2547f7 --- /dev/null +++ b/tests/remote-builds.nix @@ -0,0 +1,73 @@ +# Test Nix's remote build feature. + +{ pkgs, ... }: + +let + + # The configuration of the build slaves. + slave = + { config, pkgs, ... }: + { services.openssh.enable = true; + virtualisation.writableStore = true; + }; + + # Trivial Nix expression to build remotely. + expr = config: pkgs.writeText "expr.nix" + '' + let utils = builtins.storePath ${config.system.build.extraUtils}; in + derivation { + name = "hello"; + system = "i686-linux"; + PATH = "''${utils}/bin"; + builder = "''${utils}/bin/sh"; + args = [ "-c" "echo Hello; mkdir $out; cat /proc/sys/kernel/hostname > $out/host" ]; + } + ''; + +in + +{ + + nodes = + { slave1 = slave; + #slave2 = slave; + + client = + { config, pkgs, ... }: + { nix.maxJobs = 0; # force remote building + nix.distributedBuilds = true; + nix.buildMachines = + [ { hostName = "slave1"; + sshUser = "root"; + sshKey = "/root/.ssh/id_dsa"; + system = "i686-linux"; + maxJobs = 1; + } + ]; + virtualisation.writableStore = true; + virtualisation.pathsInNixDB = [ config.system.build.extraUtils ]; + }; + }; + + testScript = { nodes }: + '' + startAll; + + # Create an SSH key on the client. + my $key = `${pkgs.openssh}/bin/ssh-keygen -t dsa -f key -N ""`; + $client->succeed("mkdir -m 700 /root/.ssh"); + $client->copyFileFromHost("key", "/root/.ssh/id_dsa"); + $client->succeed("chmod 600 /root/.ssh/id_dsa"); + + # Install the SSH key on the slaves. + $slave1->succeed("mkdir -m 700 /root/.ssh"); + $slave1->copyFileFromHost("key.pub", "/root/.ssh/authorized_keys"); + $slave1->waitForJob("sshd"); + $client->succeed("ssh -o StrictHostKeyChecking=no slave1 'echo hello world'"); + + # Perform a build and check that it was performed on the slave. + my $out = $client->succeed("nix-build ${expr nodes.client.config}"); + $slave1->succeed("test -e $out"); + ''; + +}