1import ../make-test-python.nix ({ lib, ... }:
2
3{
4 name = "initrd-network-ssh";
5 meta = with lib.maintainers; {
6 maintainers = [ willibutz emily ];
7 };
8
9 nodes = with lib; {
10 server =
11 { config, ... }:
12 {
13 boot.kernelParams = [
14 "ip=${config.networking.primaryIPAddress}:::255.255.255.0::eth1:none"
15 ];
16 boot.initrd.network = {
17 enable = true;
18 ssh = {
19 enable = true;
20 authorizedKeys = [ (readFile ./id_ed25519.pub) ];
21 port = 22;
22 hostKeys = [ ./ssh_host_ed25519_key ];
23 };
24 };
25 boot.initrd.preLVMCommands = ''
26 while true; do
27 if [ -f fnord ]; then
28 poweroff
29 fi
30 sleep 1
31 done
32 '';
33 };
34
35 client =
36 { config, ... }:
37 {
38 environment.etc = {
39 knownHosts = {
40 text = concatStrings [
41 "server,"
42 "${toString (head (splitString " " (
43 toString (elemAt (splitString "\n" config.networking.extraHosts) 2)
44 )))} "
45 "${readFile ./ssh_host_ed25519_key.pub}"
46 ];
47 };
48 sshKey = {
49 source = ./id_ed25519;
50 mode = "0600";
51 };
52 };
53 };
54 };
55
56 testScript = ''
57 start_all()
58 client.wait_for_unit("network.target")
59
60
61 def ssh_is_up(_) -> bool:
62 status, _ = client.execute("nc -z server 22")
63 return status == 0
64
65
66 with client.nested("waiting for SSH server to come up"):
67 retry(ssh_is_up)
68
69
70 client.succeed(
71 "ssh -i /etc/sshKey -o UserKnownHostsFile=/etc/knownHosts server 'touch /fnord'"
72 )
73 client.shutdown()
74 '';
75})