1import ../make-test.nix ({ lib, ... }:
2
3{
4 name = "initrd-network-ssh";
5 meta = with lib.maintainers; {
6 maintainers = [ willibutz ];
7 };
8
9 nodes = with lib; rec {
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 ./openssh.pub}" ];
21 port = 22;
22 hostRSAKey = ./dropbear.priv;
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.knownHosts = {
39 text = concatStrings [
40 "server,"
41 "${toString (head (splitString " " (
42 toString (elemAt (splitString "\n" config.networking.extraHosts) 2)
43 )))} "
44 "${readFile ./dropbear.pub}"
45 ];
46 };
47 };
48 };
49
50 testScript = ''
51 startAll;
52 $client->waitForUnit("network.target");
53 $client->copyFileFromHost("${./openssh.priv}","/etc/sshKey");
54 $client->succeed("chmod 0600 /etc/sshKey");
55 $client->waitUntilSucceeds("ping -c 1 server");
56 $client->succeed("ssh -i /etc/sshKey -o UserKnownHostsFile=/etc/knownHosts server 'touch /fnord'");
57 $client->shutdown;
58 '';
59})