2011-10-11 13:06:59 +00:00
|
|
|
# Test Nix's remote build feature.
|
|
|
|
|
2017-12-22 10:33:34 +00:00
|
|
|
{ nixpkgs, system, nix }:
|
2011-10-11 13:06:59 +00:00
|
|
|
|
2017-12-22 10:33:34 +00:00
|
|
|
with import (nixpkgs + "/nixos/lib/testing.nix") { inherit system; };
|
2011-10-11 13:06:59 +00:00
|
|
|
|
2014-04-15 13:32:27 +00:00
|
|
|
makeTest (
|
2011-10-11 13:06:59 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
# The configuration of the build slaves.
|
|
|
|
slave =
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{ services.openssh.enable = true;
|
|
|
|
virtualisation.writableStore = true;
|
2014-12-05 18:25:38 +00:00
|
|
|
nix.package = nix;
|
2017-02-21 14:21:56 +00:00
|
|
|
nix.useSandbox = true;
|
2011-10-11 13:06:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# Trivial Nix expression to build remotely.
|
|
|
|
expr = config: nr: pkgs.writeText "expr.nix"
|
|
|
|
''
|
|
|
|
let utils = builtins.storePath ${config.system.build.extraUtils}; in
|
|
|
|
derivation {
|
|
|
|
name = "hello-${toString nr}";
|
|
|
|
system = "i686-linux";
|
|
|
|
PATH = "''${utils}/bin";
|
|
|
|
builder = "''${utils}/bin/sh";
|
2014-12-11 08:58:29 +00:00
|
|
|
args = [ "-c" "if [ ${toString nr} = 5 ]; then echo FAIL; exit 1; fi; echo Hello; mkdir $out $foo; cat /proc/sys/kernel/hostname > $out/host; ln -s $out $foo/bar; sleep 10" ];
|
2014-07-14 10:19:27 +00:00
|
|
|
outputs = [ "out" "foo" ];
|
2011-10-11 13:06:59 +00:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
{ hostName = "slave2";
|
|
|
|
sshUser = "root";
|
|
|
|
sshKey = "/root/.ssh/id_dsa";
|
|
|
|
system = "i686-linux";
|
|
|
|
maxJobs = 1;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
virtualisation.writableStore = true;
|
|
|
|
virtualisation.pathsInNixDB = [ config.system.build.extraUtils ];
|
2014-04-15 13:32:27 +00:00
|
|
|
nix.package = nix;
|
2014-07-24 09:50:05 +00:00
|
|
|
nix.binaryCaches = [ ];
|
2014-09-05 09:49:07 +00:00
|
|
|
programs.ssh.extraConfig = "ConnectTimeout 30";
|
2011-10-11 13:06:59 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = { nodes }:
|
|
|
|
''
|
|
|
|
startAll;
|
|
|
|
|
|
|
|
# Create an SSH key on the client.
|
|
|
|
my $key = `${pkgs.openssh}/bin/ssh-keygen -t dsa -f key -N ""`;
|
2014-09-05 09:49:07 +00:00
|
|
|
$client->succeed("mkdir -p -m 700 /root/.ssh");
|
2011-10-11 13:06:59 +00:00
|
|
|
$client->copyFileFromHost("key", "/root/.ssh/id_dsa");
|
|
|
|
$client->succeed("chmod 600 /root/.ssh/id_dsa");
|
|
|
|
|
|
|
|
# Install the SSH key on the slaves.
|
2013-03-08 00:24:59 +00:00
|
|
|
$client->waitForUnit("network.target");
|
2011-10-11 13:06:59 +00:00
|
|
|
foreach my $slave ($slave1, $slave2) {
|
2014-09-05 09:49:07 +00:00
|
|
|
$slave->succeed("mkdir -p -m 700 /root/.ssh");
|
2011-10-11 13:06:59 +00:00
|
|
|
$slave->copyFileFromHost("key.pub", "/root/.ssh/authorized_keys");
|
2013-03-08 00:24:59 +00:00
|
|
|
$slave->waitForUnit("sshd");
|
2011-10-11 13:06:59 +00:00
|
|
|
$client->succeed("ssh -o StrictHostKeyChecking=no " . $slave->name() . " 'echo hello world'");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Perform a build and check that it was performed on the slave.
|
2017-11-25 00:03:23 +00:00
|
|
|
my $out = $client->succeed(
|
|
|
|
"nix-build ${expr nodes.client.config 1} 2> build-output",
|
|
|
|
"grep -q Hello build-output"
|
|
|
|
);
|
2011-10-11 13:06:59 +00:00
|
|
|
$slave1->succeed("test -e $out");
|
|
|
|
|
|
|
|
# And a parallel build.
|
|
|
|
my ($out1, $out2) = split /\s/,
|
2014-07-14 10:19:27 +00:00
|
|
|
$client->succeed('nix-store -r $(nix-instantiate ${expr nodes.client.config 2})\!out $(nix-instantiate ${expr nodes.client.config 3})\!out');
|
2011-10-11 13:06:59 +00:00
|
|
|
$slave1->succeed("test -e $out1 -o -e $out2");
|
|
|
|
$slave2->succeed("test -e $out1 -o -e $out2");
|
|
|
|
|
2014-07-24 10:10:06 +00:00
|
|
|
# And a failing build.
|
|
|
|
$client->fail("nix-build ${expr nodes.client.config 5}");
|
|
|
|
|
2011-10-11 13:06:59 +00:00
|
|
|
# Test whether the build hook automatically skips unavailable slaves.
|
|
|
|
$slave1->block;
|
|
|
|
$client->succeed("nix-build ${expr nodes.client.config 4}");
|
|
|
|
'';
|
|
|
|
|
|
|
|
})
|