base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12
[NixPkgs.git] / nixos / tests / amazon-init-shell.nix
blobda4480ed5778854cb052e6e11e4030f8645da24c
1 # This test verifies that the amazon-init service can treat the `user-data` ec2
2 # metadata file as a shell script. If amazon-init detects that `user-data` is a
3 # script (based on the presence of the shebang #! line) it executes it and
4 # exits.
5 # Note that other tests verify that amazon-init can treat user-data as a nixos
6 # configuration expression.
8 { system ? builtins.currentSystem,
9   config ? {},
10   pkgs ? import ../.. { inherit system config; }
13 with import ../lib/testing-python.nix { inherit system pkgs; };
14 with pkgs.lib;
16 makeTest {
17   name = "amazon-init";
18   meta = with maintainers; {
19     maintainers = [ urbas ];
20   };
21   nodes.machine = { lib, pkgs, ... }:
22   {
23     imports = [ ../modules/profiles/headless.nix ../modules/virtualisation/amazon-init.nix ];
24     services.openssh.enable = true;
25     system.switch.enable = true;
26     networking.hostName = "";
27     environment.etc."ec2-metadata/user-data" = {
28       text = ''
29         #!/usr/bin/bash
31         echo successful > /tmp/evidence
33         # Emulate running nixos-rebuild switch, just without any building.
34         # https://github.com/nixos/nixpkgs/blob/4c62505847d88f16df11eff3c81bf9a453a4979e/nixos/modules/virtualisation/amazon-init.nix#L55
35         /run/current-system/bin/switch-to-configuration test
36       '';
37     };
38   };
39   testScript = ''
40     # To wait until amazon-init terminates its run
41     unnamed.wait_for_unit("amazon-init.service")
43     unnamed.succeed("grep -q successful /tmp/evidence")
44   '';