0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

nixos/tests: add nixos-rebuild-target-host-ng

This commit is contained in:
Thiago Kenji Okada 2024-12-10 12:50:12 +00:00
parent 1d3c452d63
commit 1b5fac463b
3 changed files with 31 additions and 6 deletions

View file

@ -720,7 +720,14 @@ in {
imports = [ ./nixos-rebuild-specialisations.nix ];
_module.args.withNg = true;
};
nixos-rebuild-target-host = runTest ./nixos-rebuild-target-host.nix;
nixos-rebuild-target-host = runTest {
imports = [ ./nixos-rebuild-target-host.nix ];
_module.args.withNg = false;
};
nixos-rebuild-target-host-ng = runTest {
imports = [ ./nixos-rebuild-target-host.nix ];
_module.args.withNg = true;
};
nixpkgs = pkgs.callPackage ../modules/misc/nixpkgs/test.nix { inherit evalMinimalConfig; };
nixseparatedebuginfod = handleTest ./nixseparatedebuginfod.nix {};
node-red = handleTest ./node-red.nix {};

View file

@ -1,4 +1,4 @@
{ hostPkgs, ... }: {
{ hostPkgs, lib, withNg, ... }: {
name = "nixos-rebuild-target-host";
# TODO: remove overlay from nixos/modules/profiles/installation-device.nix
@ -30,6 +30,7 @@
system.build.publicKey = snakeOilPublicKey;
# We don't switch on `deployer`, but we need it to have the dependencies
# available, to be picked up by system.includeBuildDependencies above.
system.rebuild.enableNg = withNg;
system.switch.enable = true;
};
@ -83,7 +84,7 @@
targetNetworkJSON = hostPkgs.writeText "target-network.json"
(builtins.toJSON nodes.target.system.build.networkConfig);
configFile = hostname: hostPkgs.writeText "configuration.nix" ''
configFile = hostname: hostPkgs.writeText "configuration.nix" /* nix */ ''
{ lib, modulesPath, ... }: {
imports = [
(modulesPath + "/virtualisation/qemu-vm.nix")
@ -100,12 +101,24 @@
forceInstall = true;
};
system.rebuild.enableNg = ${lib.boolToString withNg};
${lib.optionalString withNg /* nix */ ''
nixpkgs.overlays = [
(final: prev: {
# Set tmpdir inside nixos-rebuild-ng to test
# "Deploy works with very long TMPDIR"
nixos-rebuild-ng = prev.nixos-rebuild-ng.override { withTmpdir = "/tmp"; };
})
];
''}
# this will be asserted
networking.hostName = "${hostname}";
}
'';
in
''
/* python */ ''
start_all()
target.wait_for_open_port(22)
@ -137,7 +150,8 @@
assert target_hostname == "config-2-deployed", f"{target_hostname=}"
with subtest("Deploy to bob@target with password based sudo"):
deployer.succeed("passh -c 3 -C -p ${nodes.target.users.users.bob.password} -P \"\[sudo\] password\" nixos-rebuild switch -I nixos-config=/root/configuration-3.nix --target-host bob@target --use-remote-sudo &>/dev/console")
# TODO: investigate why --ask-sudo-password from nixos-rebuild-ng is not working here
deployer.succeed(r'${lib.optionalString withNg "NIX_SSHOPTS=-t "}passh -c 3 -C -p ${nodes.target.users.users.bob.password} -P "\[sudo\] password" nixos-rebuild switch -I nixos-config=/root/configuration-3.nix --target-host bob@target --use-remote-sudo &>/dev/console')
target_hostname = deployer.succeed("ssh alice@target cat /etc/hostname").rstrip()
assert target_hostname == "config-3-deployed", f"{target_hostname=}"

View file

@ -103,7 +103,11 @@ python3Packages.buildPythonApplication rec {
};
tests = {
inherit (nixosTests) nixos-rebuild-install-bootloader-ng nixos-rebuild-specialisations-ng;
inherit (nixosTests)
nixos-rebuild-install-bootloader-ng
nixos-rebuild-specialisations-ng
nixos-rebuild-target-host-ng
;
repl = callPackage ./tests/repl.nix { };
# NOTE: this is a passthru test rather than a build-time test because we
# want to keep the build closures small