1 { system ? builtins.currentSystem,
3 pkgs ? import ../.. { inherit system config; }
6 with import ../lib/testing-python.nix { inherit system pkgs; };
10 inherit (import ./ssh-keys.nix pkgs)
11 snakeOilPrivateKey snakeOilPublicKey;
13 metadataDrive = pkgs.stdenv.mkDerivation {
18 cat << EOF > $out/iso/user-data
23 path: /tmp/cloudinit-write-file
29 - "${snakeOilPublicKey}"
32 cat << EOF > $out/iso/meta-data
33 instance-id: iid-local01
34 local-hostname: "test"
36 - "${snakeOilPublicKey}"
39 cat << EOF > $out/iso/network-config
44 mac_address: '52:54:00:12:34:56'
47 address: '12.34.56.78'
48 netmask: '255.255.255.0'
56 ${pkgs.cdrkit}/bin/genisoimage -volid cidata -joliet -rock -o $out/metadata.iso $out/iso
62 meta.maintainers = with pkgs.lib.maintainers; [ lewo illustris ];
63 nodes.machine = { ... }:
65 virtualisation.qemu.options = [ "-cdrom" "${metadataDrive}/metadata.iso" ];
66 services.cloud-init = {
68 network.enable = true;
70 services.openssh.enable = true;
71 networking.hostName = "";
72 networking.useDHCP = false;
75 # To wait until cloud-init terminates its run
76 unnamed.wait_for_unit("cloud-init-local.service")
77 unnamed.wait_for_unit("cloud-final.service")
79 unnamed.succeed("cat /tmp/cloudinit-write-file | grep -q 'cloudinit'")
81 # install snakeoil ssh key and provision .ssh/config file
82 unnamed.succeed("mkdir -p ~/.ssh")
84 "cat ${snakeOilPrivateKey} > ~/.ssh/id_snakeoil"
86 unnamed.succeed("chmod 600 ~/.ssh/id_snakeoil")
88 unnamed.wait_for_unit("sshd.service")
90 # we should be able to log in as the root user, as well as the created nixos user
92 "timeout 10 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentityFile=~/.ssh/id_snakeoil root@localhost 'true'"
95 "timeout 10 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentityFile=~/.ssh/id_snakeoil nixos@localhost 'true'"
98 # test changing hostname via cloud-init worked
101 "timeout 10 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentityFile=~/.ssh/id_snakeoil nixos@localhost 'hostname'"
106 # check IP and route configs
107 assert "default via 12.34.56.9 dev eth0 proto static" in unnamed.succeed("ip route")
108 assert "12.34.56.0/24 dev eth0 proto kernel scope link src 12.34.56.78" in unnamed.succeed("ip route")
110 # check nameserver and search configs
111 assert "6.7.8.9" in unnamed.succeed("resolvectl status")
112 assert "example.com" in unnamed.succeed("resolvectl status")