From 1b5fac463b193e7ea607ce21e9871a061bde6bee Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 10 Dec 2024 12:50:12 +0000 Subject: [PATCH] nixos/tests: add nixos-rebuild-target-host-ng --- nixos/tests/all-tests.nix | 9 +++++++- nixos/tests/nixos-rebuild-target-host.nix | 22 ++++++++++++++++---- pkgs/by-name/ni/nixos-rebuild-ng/package.nix | 6 +++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index be786ee19d03..bcdf4d5b8013 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -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 {}; diff --git a/nixos/tests/nixos-rebuild-target-host.nix b/nixos/tests/nixos-rebuild-target-host.nix index 0e4c3e5f3999..78f189419fb1 100644 --- a/nixos/tests/nixos-rebuild-target-host.nix +++ b/nixos/tests/nixos-rebuild-target-host.nix @@ -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=}" diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/package.nix b/pkgs/by-name/ni/nixos-rebuild-ng/package.nix index 1ad39b0e686b..7dc84de9984e 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/package.nix +++ b/pkgs/by-name/ni/nixos-rebuild-ng/package.nix @@ -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