Skip to content

Commit 7c828e9

Browse files
committed
nixosTests.amazon-init-shell: test switching during amazon-init
In order to emulate the `nixos-rebuild switch` that is called if the EC2 user data is a nix expression, run the switch-to-configuration script for the current running config.
1 parent 64ec9ae commit 7c828e9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

nixos/tests/amazon-init-shell.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@ makeTest {
1818
meta = with maintainers; {
1919
maintainers = [ urbas ];
2020
};
21-
nodes.machine = { ... }:
21+
nodes.machine = { lib, pkgs, ... }:
2222
{
2323
imports = [ ../modules/profiles/headless.nix ../modules/virtualisation/amazon-init.nix ];
2424
services.openssh.enable = true;
25+
system.switch.enable = true;
2526
networking.hostName = "";
2627
environment.etc."ec2-metadata/user-data" = {
2728
text = ''
2829
#!/usr/bin/bash
2930
3031
echo successful > /tmp/evidence
32+
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
3136
'';
3237
};
3338
};

0 commit comments

Comments
 (0)