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
21 # Hack to make the partition resizing work in QEMU.
22 boot.initrd.postDeviceCommands = mkBefore ''
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}.vhd";
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";
69 sshPublicKey = snakeOilPublicKey; # That's right folks! My user's key is also the host key!
72 SSH_HOST_ED25519_KEY_PUB:${snakeOilPublicKey}
73 SSH_HOST_ED25519_KEY:${replaceStrings ["\n"] ["|"] snakeOilPrivateKey}
77 machine.wait_for_file("/etc/ec2-metadata/user-data")
78 machine.wait_for_unit("sshd.service")
80 machine.succeed("grep unknown /etc/ec2-metadata/ami-manifest-path")
82 # We have no keys configured on the client side yet, so this should fail
83 machine.fail("ssh -o BatchMode=yes localhost exit")
85 # Let's install our client private key
86 machine.succeed("mkdir -p ~/.ssh")
88 machine.copy_from_host_via_shell(
89 "${snakeOilPrivateKeyFile}", "~/.ssh/id_ed25519"
91 machine.succeed("chmod 600 ~/.ssh/id_ed25519")
93 # We haven't configured the host key yet, so this should still fail
94 machine.fail("ssh -o BatchMode=yes localhost exit")
96 # Add the host key; ssh should finally succeed
98 "echo localhost,127.0.0.1 ${snakeOilPublicKey} > ~/.ssh/known_hosts"
100 machine.succeed("ssh -o BatchMode=yes localhost exit")
102 # Test whether the root disk was resized.
103 blocks, block_size = map(int, machine.succeed("stat -c %b:%S -f /").split(":"))
105 assert 9.7 * GB <= blocks * block_size <= 10 * GB
107 # Just to make sure resizing is idempotent.
110 machine.wait_for_file("/etc/ec2-metadata/user-data")
114 boot-ec2-config = makeEc2Test {
115 name = "config-userdata";
116 meta.broken = true; # amazon-init wants to download from the internet while building the system
118 sshPublicKey = snakeOilPublicKey;
120 # ### https://nixos.org/channels/nixos-unstable nixos
126 <nixpkgs/nixos/modules/virtualisation/amazon-image.nix>
127 <nixpkgs/nixos/modules/testing/test-instrumentation.nix>
128 <nixpkgs/nixos/modules/profiles/qemu-guest.nix>
130 environment.etc.testFile = {
134 networking.hostName = "ec2-test-vm"; # required by services.httpd
138 adminAddr = "test@example.org";
139 virtualHosts.localhost.documentRoot = "''${pkgs.valgrind.doc}/share/doc/valgrind/html";
141 networking.firewall.allowedTCPPorts = [ 80 ];
147 # amazon-init must succeed. if it fails, make the test fail
148 # immediately instead of timing out in wait_for_file.
149 machine.wait_for_unit("amazon-init.service")
151 machine.wait_for_file("/etc/testFile")
152 assert "whoa" in machine.succeed("cat /etc/testFile")
154 machine.wait_for_unit("httpd.service")
155 assert "Valgrind" in machine.succeed("curl http://localhost")