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-final.service")
78 unnamed.succeed("cat /tmp/cloudinit-write-file | grep -q 'cloudinit'")
80 # install snakeoil ssh key and provision .ssh/config file
81 unnamed.succeed("mkdir -p ~/.ssh")
83 "cat ${snakeOilPrivateKey} > ~/.ssh/id_snakeoil"
85 unnamed.succeed("chmod 600 ~/.ssh/id_snakeoil")
87 unnamed.wait_for_unit("sshd.service")
89 # we should be able to log in as the root user, as well as the created nixos user
91 "timeout 10 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentityFile=~/.ssh/id_snakeoil root@localhost 'true'"
94 "timeout 10 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentityFile=~/.ssh/id_snakeoil nixos@localhost 'true'"
97 # test changing hostname via cloud-init worked
100 "timeout 10 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentityFile=~/.ssh/id_snakeoil nixos@localhost 'hostname'"
105 # check IP and route configs
106 assert "default via 12.34.56.9 dev eth0 proto static" in unnamed.succeed("ip route")
107 assert "12.34.56.0/24 dev eth0 proto kernel scope link src 12.34.56.78" in unnamed.succeed("ip route")
109 # check nameserver and search configs
110 assert "6.7.8.9" in unnamed.succeed("resolvectl status")
111 assert "example.com" in unnamed.succeed("resolvectl status")