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