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