1import ./make-test-python.nix (
2 { lib, ... }:
3 {
4 name = "systemd-initrd-network-ssh";
5 meta.maintainers = [ lib.maintainers.elvishjerricco ];
6
7 nodes = {
8 server =
9 { config, pkgs, ... }:
10 {
11 testing.initrdBackdoor = true;
12 boot.initrd.systemd.enable = true;
13 boot.initrd.systemd.contents."/etc/msg".text = "foo";
14 boot.initrd.network = {
15 enable = true;
16 ssh = {
17 enable = true;
18 authorizedKeys = [ (lib.readFile ./initrd-network-ssh/id_ed25519.pub) ];
19 port = 22;
20 hostKeys = [ ./initrd-network-ssh/ssh_host_ed25519_key ];
21 };
22 };
23 };
24
25 client =
26 { config, ... }:
27 {
28 environment.etc = {
29 knownHosts = {
30 text = lib.concatStrings [
31 "server,"
32 "${toString (lib.head (lib.splitString " " (toString (lib.elemAt (lib.splitString "\n" config.networking.extraHosts) 2))))} "
33 "${lib.readFile ./initrd-network-ssh/ssh_host_ed25519_key.pub}"
34 ];
35 };
36 sshKey = {
37 source = ./initrd-network-ssh/id_ed25519;
38 mode = "0600";
39 };
40 };
41 };
42 };
43
44 testScript = ''
45 start_all()
46
47 def ssh_is_up(_) -> bool:
48 status, _ = client.execute("nc -z server 22")
49 return status == 0
50
51 client.wait_for_unit("network.target")
52 with client.nested("waiting for SSH server to come up"):
53 retry(ssh_is_up)
54
55 msg = client.succeed(
56 "ssh -i /etc/sshKey -o UserKnownHostsFile=/etc/knownHosts server 'cat /etc/msg'"
57 )
58 assert "foo" in msg
59
60 server.switch_root()
61 server.wait_for_unit("multi-user.target")
62 '';
63 }
64)