2023-07-29 01:27:17 +00:00
|
|
|
import ../make-test-python.nix ({ lib, pkgs, ... }:
|
2017-09-18 12:52:07 +00:00
|
|
|
|
2017-11-27 08:14:17 +00:00
|
|
|
{
|
2017-09-18 12:52:07 +00:00
|
|
|
name = "initrd-network-ssh";
|
2023-07-29 01:27:17 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [ willibutz emily ];
|
2017-09-18 12:52:07 +00:00
|
|
|
|
2023-07-29 01:27:17 +00:00
|
|
|
nodes = {
|
2017-09-18 12:52:07 +00:00
|
|
|
server =
|
2018-07-20 20:56:59 +00:00
|
|
|
{ config, ... }:
|
2017-09-18 12:52:07 +00:00
|
|
|
{
|
|
|
|
boot.kernelParams = [
|
2017-12-03 04:14:54 +00:00
|
|
|
"ip=${config.networking.primaryIPAddress}:::255.255.255.0::eth1:none"
|
2017-09-18 12:52:07 +00:00
|
|
|
];
|
|
|
|
boot.initrd.network = {
|
|
|
|
enable = true;
|
|
|
|
ssh = {
|
|
|
|
enable = true;
|
2023-07-29 01:27:17 +00:00
|
|
|
authorizedKeys = [ (lib.readFile ./id_ed25519.pub) ];
|
2017-09-18 12:52:07 +00:00
|
|
|
port = 22;
|
2020-03-14 18:29:08 +00:00
|
|
|
hostKeys = [ ./ssh_host_ed25519_key ];
|
2017-09-18 12:52:07 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
boot.initrd.preLVMCommands = ''
|
|
|
|
while true; do
|
|
|
|
if [ -f fnord ]; then
|
|
|
|
poweroff
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
client =
|
2018-07-20 20:56:59 +00:00
|
|
|
{ config, ... }:
|
2017-09-18 12:52:07 +00:00
|
|
|
{
|
2019-11-06 15:48:07 +00:00
|
|
|
environment.etc = {
|
|
|
|
knownHosts = {
|
2023-07-29 01:27:17 +00:00
|
|
|
text = lib.concatStrings [
|
2019-11-06 15:48:07 +00:00
|
|
|
"server,"
|
2023-07-29 01:27:17 +00:00
|
|
|
"${toString (lib.head (lib.splitString " " (
|
|
|
|
toString (lib.elemAt (lib.splitString "\n" config.networking.extraHosts) 2)
|
2019-11-06 15:48:07 +00:00
|
|
|
)))} "
|
2023-07-29 01:27:17 +00:00
|
|
|
"${lib.readFile ./ssh_host_ed25519_key.pub}"
|
2019-11-06 15:48:07 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
sshKey = {
|
2020-03-14 18:29:08 +00:00
|
|
|
source = ./id_ed25519;
|
2019-11-06 15:48:07 +00:00
|
|
|
mode = "0600";
|
|
|
|
};
|
2017-09-18 12:52:07 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2019-11-06 15:48:07 +00:00
|
|
|
start_all()
|
|
|
|
client.wait_for_unit("network.target")
|
2020-03-14 18:29:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
def ssh_is_up(_) -> bool:
|
|
|
|
status, _ = client.execute("nc -z server 22")
|
|
|
|
return status == 0
|
|
|
|
|
|
|
|
|
|
|
|
with client.nested("waiting for SSH server to come up"):
|
|
|
|
retry(ssh_is_up)
|
|
|
|
|
|
|
|
|
2019-11-06 15:48:07 +00:00
|
|
|
client.succeed(
|
|
|
|
"ssh -i /etc/sshKey -o UserKnownHostsFile=/etc/knownHosts server 'touch /fnord'"
|
|
|
|
)
|
|
|
|
client.shutdown()
|
2017-09-18 12:52:07 +00:00
|
|
|
'';
|
|
|
|
})
|