aboutsummaryrefslogtreecommitdiff
path: root/tests/nixos
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-07 03:02:22 +0100
committereldritch horrors <pennae@lix.systems>2024-03-06 21:32:47 -0700
commitf10e673272425fd6f7b6d93a8f62bd7ff378e8c8 (patch)
tree979abbec00add87928b1740d8d248dea9d76ba5a /tests/nixos
parent097acae35bd99cebd6cdb22cd6e498f3a50951f1 (diff)
tests/nixos/remote-builds*: Inline module + format
(cherry picked from commit 5167351efbee5c5a7390510eb720c31c6976f4d9) Change-Id: I0caba23b589ed428d08895d7b8f0c22532bd259e
Diffstat (limited to 'tests/nixos')
-rw-r--r--tests/nixos/remote-builds-ssh-ng.nix151
-rw-r--r--tests/nixos/remote-builds.nix167
2 files changed, 158 insertions, 160 deletions
diff --git a/tests/nixos/remote-builds-ssh-ng.nix b/tests/nixos/remote-builds-ssh-ng.nix
index c75ad7253..cca4066f3 100644
--- a/tests/nixos/remote-builds-ssh-ng.nix
+++ b/tests/nixos/remote-builds-ssh-ng.nix
@@ -28,96 +28,95 @@ let
in
{
- name = lib.mkDefault "remote-builds-ssh-ng";
-
- # TODO expand module shorthand syntax instead of use imports
- imports = [{
- options = {
- builders.config = lib.mkOption {
- type = lib.types.deferredModule;
- description = ''
- Configuration to add to the builder nodes.
- '';
- default = { };
- };
+ options = {
+ builders.config = lib.mkOption {
+ type = lib.types.deferredModule;
+ description = ''
+ Configuration to add to the builder nodes.
+ '';
+ default = { };
};
- }];
-
- nodes =
- { builder =
- { config, pkgs, ... }:
- {
- imports = [ test.config.builders.config ];
- services.openssh.enable = true;
- virtualisation.writableStore = true;
- nix.settings.sandbox = true;
- nix.settings.substituters = lib.mkForce [ ];
- };
+ };
- client =
- { config, lib, pkgs, ... }:
- { nix.settings.max-jobs = 0; # force remote building
- nix.distributedBuilds = true;
- nix.buildMachines =
- [ { hostName = "builder";
- sshUser = "root";
- sshKey = "/root/.ssh/id_ed25519";
- system = "i686-linux";
- maxJobs = 1;
- protocol = "ssh-ng";
- }
- ];
+ config = {
+ name = lib.mkDefault "remote-builds-ssh-ng";
+
+ nodes =
+ { builder =
+ { config, pkgs, ... }:
+ {
+ imports = [ test.config.builders.config ];
+ services.openssh.enable = true;
virtualisation.writableStore = true;
- virtualisation.additionalPaths = [ config.system.build.extraUtils ];
+ nix.settings.sandbox = true;
nix.settings.substituters = lib.mkForce [ ];
- programs.ssh.extraConfig = "ConnectTimeout 30";
};
- };
- testScript = { nodes }: ''
- # fmt: off
- import subprocess
+ client =
+ { config, lib, pkgs, ... }:
+ { nix.settings.max-jobs = 0; # force remote building
+ nix.distributedBuilds = true;
+ nix.buildMachines =
+ [ { hostName = "builder";
+ sshUser = "root";
+ sshKey = "/root/.ssh/id_ed25519";
+ system = "i686-linux";
+ maxJobs = 1;
+ protocol = "ssh-ng";
+ }
+ ];
+ virtualisation.writableStore = true;
+ virtualisation.additionalPaths = [ config.system.build.extraUtils ];
+ nix.settings.substituters = lib.mkForce [ ];
+ programs.ssh.extraConfig = "ConnectTimeout 30";
+ };
+ };
+
+ testScript = { nodes }: ''
+ # fmt: off
+ import subprocess
- start_all()
+ start_all()
- # Create an SSH key on the client.
- subprocess.run([
- "${hostPkgs.openssh}/bin/ssh-keygen", "-t", "ed25519", "-f", "key", "-N", ""
- ], capture_output=True, check=True)
- client.succeed("mkdir -p -m 700 /root/.ssh")
- client.copy_from_host("key", "/root/.ssh/id_ed25519")
- client.succeed("chmod 600 /root/.ssh/id_ed25519")
+ # Create an SSH key on the client.
+ subprocess.run([
+ "${hostPkgs.openssh}/bin/ssh-keygen", "-t", "ed25519", "-f", "key", "-N", ""
+ ], capture_output=True, check=True)
+ client.succeed("mkdir -p -m 700 /root/.ssh")
+ client.copy_from_host("key", "/root/.ssh/id_ed25519")
+ client.succeed("chmod 600 /root/.ssh/id_ed25519")
- # Install the SSH key on the builder.
- client.wait_for_unit("network.target")
- builder.succeed("mkdir -p -m 700 /root/.ssh")
- builder.copy_from_host("key.pub", "/root/.ssh/authorized_keys")
- builder.wait_for_unit("sshd")
- client.succeed(f"ssh -o StrictHostKeyChecking=no {builder.name} 'echo hello world'")
+ # Install the SSH key on the builder.
+ client.wait_for_unit("network.target")
+ builder.succeed("mkdir -p -m 700 /root/.ssh")
+ builder.copy_from_host("key.pub", "/root/.ssh/authorized_keys")
+ builder.wait_for_unit("sshd")
+ client.succeed(f"ssh -o StrictHostKeyChecking=no {builder.name} 'echo hello world'")
- # Perform a build
- out = client.succeed("nix-build ${expr nodes.client.config 1} 2> build-output")
+ # Perform a build
+ out = client.succeed("nix-build ${expr nodes.client 1} 2> build-output")
- # Verify that the build was done on the builder
- builder.succeed(f"test -e {out.strip()}")
+ # Verify that the build was done on the builder
+ builder.succeed(f"test -e {out.strip()}")
- # Print the build log, prefix the log lines to avoid nix intercepting lines starting with @nix
- buildOutput = client.succeed("sed -e 's/^/build-output:/' build-output")
- print(buildOutput)
+ # Print the build log, prefix the log lines to avoid nix intercepting lines starting with @nix
+ buildOutput = client.succeed("sed -e 's/^/build-output:/' build-output")
+ print(buildOutput)
- # Make sure that we get the expected build output
- client.succeed("grep -qF Hello build-output")
+ # Make sure that we get the expected build output
+ client.succeed("grep -qF Hello build-output")
- # We don't want phase reporting in the build output
- client.fail("grep -qF '@nix' build-output")
+ # We don't want phase reporting in the build output
+ client.fail("grep -qF '@nix' build-output")
- # Get the log file
- client.succeed(f"nix-store --read-log {out.strip()} > log-output")
- # Prefix the log lines to avoid nix intercepting lines starting with @nix
- logOutput = client.succeed("sed -e 's/^/log-file:/' log-output")
- print(logOutput)
+ # Get the log file
+ client.succeed(f"nix-store --read-log {out.strip()} > log-output")
+ # Prefix the log lines to avoid nix intercepting lines starting with @nix
+ logOutput = client.succeed("sed -e 's/^/log-file:/' log-output")
+ print(logOutput)
- # Check that we get phase reporting in the log file
- client.succeed("grep -q '@nix {\"action\":\"setPhase\",\"phase\":\"buildPhase\"}' log-output")
- '';
+ # Check that we get phase reporting in the log file
+ client.succeed("grep -q '@nix {\"action\":\"setPhase\",\"phase\":\"buildPhase\"}' log-output")
+ '';
+ };
}
diff --git a/tests/nixos/remote-builds.nix b/tests/nixos/remote-builds.nix
index eae1ccd88..423b9d171 100644
--- a/tests/nixos/remote-builds.nix
+++ b/tests/nixos/remote-builds.nix
@@ -37,90 +37,89 @@ let
in
{
- name = lib.mkDefault "remote-builds";
-
- # TODO expand module shorthand syntax instead of use imports
- imports = [{
- options = {
- builders.config = lib.mkOption {
- type = lib.types.deferredModule;
- description = ''
- Configuration to add to the builder nodes.
- '';
- default = { };
- };
- };
- }];
-
- nodes =
- { builder1 = builder;
- builder2 = builder;
-
- client =
- { config, lib, pkgs, ... }:
- { nix.settings.max-jobs = 0; # force remote building
- nix.distributedBuilds = true;
- nix.buildMachines =
- [ { hostName = "builder1";
- sshUser = "root";
- sshKey = "/root/.ssh/id_ed25519";
- system = "i686-linux";
- maxJobs = 1;
- }
- { hostName = "builder2";
- sshUser = "root";
- sshKey = "/root/.ssh/id_ed25519";
- system = "i686-linux";
- maxJobs = 1;
- }
- ];
- virtualisation.writableStore = true;
- virtualisation.additionalPaths = [ config.system.build.extraUtils ];
- nix.settings.substituters = lib.mkForce [ ];
- programs.ssh.extraConfig = "ConnectTimeout 30";
- };
+ options = {
+ builders.config = lib.mkOption {
+ type = lib.types.deferredModule;
+ description = ''
+ Configuration to add to the builder nodes.
+ '';
+ default = { };
};
+ };
+
+ config = {
+ name = lib.mkDefault "remote-builds";
+
+ nodes =
+ { builder1 = builder;
+ builder2 = builder;
+
+ client =
+ { config, lib, pkgs, ... }:
+ { nix.settings.max-jobs = 0; # force remote building
+ nix.distributedBuilds = true;
+ nix.buildMachines =
+ [ { hostName = "builder1";
+ sshUser = "root";
+ sshKey = "/root/.ssh/id_ed25519";
+ system = "i686-linux";
+ maxJobs = 1;
+ }
+ { hostName = "builder2";
+ sshUser = "root";
+ sshKey = "/root/.ssh/id_ed25519";
+ system = "i686-linux";
+ maxJobs = 1;
+ }
+ ];
+ virtualisation.writableStore = true;
+ virtualisation.additionalPaths = [ config.system.build.extraUtils ];
+ nix.settings.substituters = lib.mkForce [ ];
+ programs.ssh.extraConfig = "ConnectTimeout 30";
+ };
+ };
- testScript = { nodes }: ''
- # fmt: off
- import subprocess
-
- start_all()
-
- # Create an SSH key on the client.
- subprocess.run([
- "${hostPkgs.openssh}/bin/ssh-keygen", "-t", "ed25519", "-f", "key", "-N", ""
- ], capture_output=True, check=True)
- client.succeed("mkdir -p -m 700 /root/.ssh")
- client.copy_from_host("key", "/root/.ssh/id_ed25519")
- client.succeed("chmod 600 /root/.ssh/id_ed25519")
-
- # Install the SSH key on the builders.
- client.wait_for_unit("network.target")
- for builder in [builder1, builder2]:
- builder.succeed("mkdir -p -m 700 /root/.ssh")
- builder.copy_from_host("key.pub", "/root/.ssh/authorized_keys")
- builder.wait_for_unit("sshd")
- client.succeed(f"ssh -o StrictHostKeyChecking=no {builder.name} 'echo hello world'")
-
- # Perform a build and check that it was performed on the builder.
- out = client.succeed(
- "nix-build ${expr nodes.client.config 1} 2> build-output",
- "grep -q Hello build-output"
- )
- builder1.succeed(f"test -e {out}")
-
- # And a parallel build.
- paths = client.succeed(r'nix-store -r $(nix-instantiate ${expr nodes.client.config 2})\!out $(nix-instantiate ${expr nodes.client.config 3})\!out')
- out1, out2 = paths.split()
- builder1.succeed(f"test -e {out1} -o -e {out2}")
- builder2.succeed(f"test -e {out1} -o -e {out2}")
-
- # And a failing build.
- client.fail("nix-build ${expr nodes.client.config 5}")
-
- # Test whether the build hook automatically skips unavailable builders.
- builder1.block()
- client.succeed("nix-build ${expr nodes.client.config 4}")
- '';
+ testScript = { nodes }: ''
+ # fmt: off
+ import subprocess
+
+ start_all()
+
+ # Create an SSH key on the client.
+ subprocess.run([
+ "${hostPkgs.openssh}/bin/ssh-keygen", "-t", "ed25519", "-f", "key", "-N", ""
+ ], capture_output=True, check=True)
+ client.succeed("mkdir -p -m 700 /root/.ssh")
+ client.copy_from_host("key", "/root/.ssh/id_ed25519")
+ client.succeed("chmod 600 /root/.ssh/id_ed25519")
+
+ # Install the SSH key on the builders.
+ client.wait_for_unit("network.target")
+ for builder in [builder1, builder2]:
+ builder.succeed("mkdir -p -m 700 /root/.ssh")
+ builder.copy_from_host("key.pub", "/root/.ssh/authorized_keys")
+ builder.wait_for_unit("sshd")
+ client.succeed(f"ssh -o StrictHostKeyChecking=no {builder.name} 'echo hello world'")
+
+ # Perform a build and check that it was performed on the builder.
+ out = client.succeed(
+ "nix-build ${expr nodes.client 1} 2> build-output",
+ "grep -q Hello build-output"
+ )
+ builder1.succeed(f"test -e {out}")
+
+ # And a parallel build.
+ paths = client.succeed(r'nix-store -r $(nix-instantiate ${expr nodes.client 2})\!out $(nix-instantiate ${expr nodes.client 3})\!out')
+ out1, out2 = paths.split()
+ builder1.succeed(f"test -e {out1} -o -e {out2}")
+ builder2.succeed(f"test -e {out1} -o -e {out2}")
+
+ # And a failing build.
+ client.fail("nix-build ${expr nodes.client 5}")
+
+ # Test whether the build hook automatically skips unavailable builders.
+ builder1.block()
+ client.succeed("nix-build ${expr nodes.client 4}")
+ '';
+ };
}