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 # In a NixOS test the serial console is occupied by the "backdoor"
26 # (see testing/test-instrumentation.nix) and is incompatible with
27 # the configuration in virtualisation/amazon-image.nix.
28 systemd.services."serial-getty@ttyS0".enable = mkForce false;
30 # Needed by nixos-rebuild due to the lack of network
31 # access. Determined by trial and error.
32 system.extraDependencies = with pkgs; ( [
33 # Needed for a nixos-rebuild.
45 # These are used in the configure-from-userdata tests
46 # for EC2. Httpd and valgrind are requested by the
56 image = "${imageCfg.system.build.amazonImage}/${imageCfg.amazonImage.name}.vhd";
58 sshKeys = import ./ssh-keys.nix pkgs;
59 snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text;
60 snakeOilPrivateKeyFile = pkgs.writeText "private-key" snakeOilPrivateKey;
61 snakeOilPublicKey = sshKeys.snakeOilPublicKey;
64 boot-ec2-nixops = makeEc2Test {
65 name = "nixops-userdata";
67 sshPublicKey = snakeOilPublicKey; # That's right folks! My user's key is also the host key!
70 SSH_HOST_ED25519_KEY_PUB:${snakeOilPublicKey}
71 SSH_HOST_ED25519_KEY:${replaceStrings ["\n"] ["|"] snakeOilPrivateKey}
75 machine.wait_for_file("/etc/ec2-metadata/user-data")
76 machine.wait_for_unit("sshd.service")
78 machine.succeed("grep unknown /etc/ec2-metadata/ami-manifest-path")
80 # We have no keys configured on the client side yet, so this should fail
81 machine.fail("ssh -o BatchMode=yes localhost exit")
83 # Let's install our client private key
84 machine.succeed("mkdir -p ~/.ssh")
86 machine.copy_from_host_via_shell(
87 "${snakeOilPrivateKeyFile}", "~/.ssh/id_ed25519"
89 machine.succeed("chmod 600 ~/.ssh/id_ed25519")
91 # We haven't configured the host key yet, so this should still fail
92 machine.fail("ssh -o BatchMode=yes localhost exit")
94 # Add the host key; ssh should finally succeed
96 "echo localhost,127.0.0.1 ${snakeOilPublicKey} > ~/.ssh/known_hosts"
98 machine.succeed("ssh -o BatchMode=yes localhost exit")
100 # Test whether the root disk was resized.
101 blocks, block_size = map(int, machine.succeed("stat -c %b:%S -f /").split(":"))
103 assert 9.7 * GB <= blocks * block_size <= 10 * GB
105 # Just to make sure resizing is idempotent.
108 machine.wait_for_file("/etc/ec2-metadata/user-data")
112 boot-ec2-config = makeEc2Test {
113 name = "config-userdata";
114 meta.broken = true; # amazon-init wants to download from the internet while building the system
116 sshPublicKey = snakeOilPublicKey;
118 # ### https://nixos.org/channels/nixos-unstable nixos
124 <nixpkgs/nixos/modules/virtualisation/amazon-image.nix>
125 <nixpkgs/nixos/modules/testing/test-instrumentation.nix>
126 <nixpkgs/nixos/modules/profiles/qemu-guest.nix>
128 environment.etc.testFile = {
132 networking.hostName = "ec2-test-vm"; # required by services.httpd
136 adminAddr = "test@example.org";
137 virtualHosts.localhost.documentRoot = "''${pkgs.valgrind.doc}/share/doc/valgrind/html";
139 networking.firewall.allowedTCPPorts = [ 80 ];
145 # amazon-init must succeed. if it fails, make the test fail
146 # immediately instead of timing out in wait_for_file.
147 machine.wait_for_unit("amazon-init.service")
149 machine.wait_for_file("/etc/testFile")
150 assert "whoa" in machine.succeed("cat /etc/testFile")
152 machine.wait_for_unit("httpd.service")
153 assert "Valgrind" in machine.succeed("curl http://localhost")