Skip to content

Commit 5d57604

Browse files
authored
change from-nixos-with-sudo.nix to interactive sudo-with-password test (#594)
2 parents 2cbfde7 + 1c64cc6 commit 5d57604

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

tests/from-nixos-with-sudo.nix

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,40 @@
88

99
users.users.nixos = {
1010
isNormalUser = true;
11+
password = "somespecialpassword";
1112
openssh.authorizedKeys.keyFiles = [ ./modules/ssh-keys/ssh.pub ];
1213
extraGroups = [ "wheel" ];
1314
};
1415
security.sudo.enable = true;
15-
security.sudo.wheelNeedsPassword = false;
16+
security.sudo.wheelNeedsPassword = true;
1617
};
1718
};
18-
testScript = ''
19-
start_all()
20-
installer.succeed("echo super-secret > /tmp/disk-1.key")
21-
output = installer.succeed("""
22-
nixos-anywhere \
23-
-i /root/.ssh/install_key \
24-
--debug \
25-
--kexec /etc/nixos-anywhere/kexec-installer.tar.gz \
26-
--phases kexec,disko \
27-
--disk-encryption-keys /tmp/disk-1.key /tmp/disk-1.key \
28-
--disk-encryption-keys /tmp/disk-2.key <(echo another-secret) \
29-
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
30-
nixos@installed >&2
31-
echo "disk-1.key: '$(ssh -i /root/.ssh/install_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
32-
root@installed cat /tmp/disk-1.key)'"
33-
echo "disk-2.key: '$(ssh -i /root/.ssh/install_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
34-
root@installed cat /tmp/disk-2.key)'"
35-
""")
36-
37-
assert "disk-1.key: 'super-secret'" in output, f"output does not contain expected values: {output}"
38-
assert "disk-2.key: 'another-secret'" in output, f"output does not contain expected values: {output}"
39-
'';
19+
20+
testScript =
21+
{ nodes, ... }:
22+
''
23+
start_all()
24+
25+
installer.succeed("echo super-secret > /tmp/disk-1.key")
26+
installer.wait_for_unit("getty.target")
27+
installer.wait_for_unit("multi-user.target")
28+
installer.wait_for_unit("default.target")
29+
30+
installer.wait_until_tty_matches("1",".*root.installer:.*")
31+
command="nixos-anywhere -i /root/.ssh/install_key --debug --kexec /etc/nixos-anywhere/kexec-installer.tar.gz --phases kexec,disko --disk-encryption-keys /tmp/disk-1.key /tmp/disk-1.key --disk-encryption-keys /tmp/disk-2.key <(echo another-secret) --store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install nixos@installed\n"
32+
installer.send_chars(command)
33+
34+
35+
installer.wait_until_tty_matches("1",".* password for nixos:.*")
36+
installer.send_chars("${nodes.installed.users.users.nixos.password}\n")
37+
38+
installer.wait_until_tty_matches("1",".*### Done! ###.*")
39+
installer.wait_until_tty_matches("1",".*root.installer:.*")
40+
41+
output = installer.succeed("""echo "disk-1.key: '$(ssh -i /root/.ssh/install_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@installed cat /tmp/disk-1.key)'" """)
42+
assert "disk-1.key: 'super-secret'" in output, f"output does not contain expected values: {output}"
43+
44+
output = installer.succeed("""echo "disk-2.key: '$(ssh -i /root/.ssh/install_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@installed cat /tmp/disk-2.key)'" """)
45+
assert "disk-2.key: 'another-secret'" in output, f"output does not contain expected values: {output}"
46+
'';
4047
}

tests/modules/installer.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
{ pkgs, inputs, ... }:
1+
{ pkgs, inputs, lib, ... }:
22
{
33
system.activationScripts.rsa-key = ''
44
${pkgs.coreutils}/bin/install -D -m600 ${./ssh-keys/ssh} /root/.ssh/install_key
55
'';
66

77
environment.systemPackages = [ inputs.nixos-anywhere ];
8-
8+
services.getty.autologinUser = lib.mkForce "root";
9+
console.earlySetup = true;
910
environment.etc = {
1011
"nixos-anywhere/disko".source = inputs.system-to-install.config.system.build.diskoScriptNoDeps;
1112
"nixos-anywhere/system-to-install".source = inputs.system-to-install.config.system.build.toplevel;

0 commit comments

Comments
 (0)