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