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