1 { system ? builtins.currentSystem,
3 pkgs ? import ../.. { inherit system config; }
6 with import ../lib/testing-python.nix { inherit system pkgs; };
9 with import common/ec2.nix { inherit makeTest pkgs; };
12 imageCfg = (import ../lib/eval-config.nix {
15 ../maintainers/scripts/ec2/amazon-image.nix
16 ../modules/testing/test-instrumentation.nix
17 ../modules/profiles/qemu-guest.nix
19 # Hack to make the partition resizing work in QEMU.
20 boot.initrd.postDeviceCommands = mkBefore ''
25 amazonImage.format = "qcow2";
27 # In a NixOS test the serial console is occupied by the "backdoor"
28 # (see testing/test-instrumentation.nix) and is incompatible with
29 # the configuration in virtualisation/amazon-image.nix.
30 systemd.services."serial-getty@ttyS0".enable = mkForce false;
32 # Needed by nixos-rebuild due to the lack of network
33 # access. Determined by trial and error.
34 system.extraDependencies = with pkgs; ( [
35 # Needed for a nixos-rebuild.
47 # These are used in the configure-from-userdata tests
48 # for EC2. Httpd and valgrind are requested by the
58 image = "${imageCfg.system.build.amazonImage}/${imageCfg.amazonImage.name}.qcow2";
60 sshKeys = import ./ssh-keys.nix pkgs;
61 snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;
62 snakeOilPrivateKeyFile = pkgs.writeText "private-key" snakeOilPrivateKey;
63 snakeOilPublicKey = sshKeys.snakeOilPublicKey;
66 boot-ec2-nixops = makeEc2Test {
67 name = "nixops-userdata";
70 sshPublicKey = snakeOilPublicKey; # That's right folks! My user's key is also the host key!
73 SSH_HOST_ED25519_KEY_PUB:${snakeOilPublicKey}
74 SSH_HOST_ED25519_KEY:${replaceStrings ["\n"] ["|"] snakeOilPrivateKey}
78 machine.wait_for_file("/etc/ec2-metadata/user-data")
79 machine.wait_for_unit("sshd.service")
81 machine.succeed("grep unknown /etc/ec2-metadata/ami-manifest-path")
83 # We have no keys configured on the client side yet, so this should fail
84 machine.fail("ssh -o BatchMode=yes localhost exit")
86 # Let's install our client private key
87 machine.succeed("mkdir -p ~/.ssh")
89 machine.copy_from_host_via_shell(
90 "${snakeOilPrivateKeyFile}", "~/.ssh/id_ed25519"
92 machine.succeed("chmod 600 ~/.ssh/id_ed25519")
94 # We haven't configured the host key yet, so this should still fail
95 machine.fail("ssh -o BatchMode=yes localhost exit")
97 # Add the host key; ssh should finally succeed
99 "echo localhost,127.0.0.1 ${snakeOilPublicKey} > ~/.ssh/known_hosts"
101 machine.succeed("ssh -o BatchMode=yes localhost exit", timeout=120)
103 # Test whether the root disk was resized.
104 blocks, block_size = map(int, machine.succeed("stat -c %b:%S -f /").split(":"))
106 assert 9.7 * GB <= blocks * block_size <= 10 * GB
108 # Just to make sure resizing is idempotent.
111 machine.wait_for_file("/etc/ec2-metadata/user-data")
115 boot-ec2-config = makeEc2Test {
116 name = "config-userdata";
117 meta.broken = true; # amazon-init wants to download from the internet while building the system
119 sshPublicKey = snakeOilPublicKey;
121 # ### https://nixos.org/channels/nixos-unstable nixos
127 <nixpkgs/nixos/modules/virtualisation/amazon-image.nix>
128 <nixpkgs/nixos/modules/testing/test-instrumentation.nix>
129 <nixpkgs/nixos/modules/profiles/qemu-guest.nix>
131 environment.etc.testFile = {
135 networking.hostName = "ec2-test-vm"; # required by services.httpd
139 adminAddr = "test@example.org";
140 virtualHosts.localhost.documentRoot = "''${pkgs.valgrind.doc}/share/doc/valgrind/html";
142 networking.firewall.allowedTCPPorts = [ 80 ];
148 # amazon-init must succeed. if it fails, make the test fail
149 # immediately instead of timing out in wait_for_file.
150 machine.wait_for_unit("amazon-init.service")
152 machine.wait_for_file("/etc/testFile")
153 assert "whoa" in machine.succeed("cat /etc/testFile")
155 machine.wait_for_unit("httpd.service")
156 assert "Valgrind" in machine.succeed("curl http://localhost")