amazon-init.service: fix starting services at startup

We now make it happen later in the boot process so that multi-user
has already activated, so as to not run afoul of the logic in
switch-to-configuration.pl. It's not my favorite solution, but at
least it works. Also added a check to the VM test to catch the failure
so we don't break in future.

Fixes #23121

Changed files
+21 -5
nixos
modules
virtualisation
tests
+2 -3
nixos/modules/virtualisation/amazon-init.nix
···
inherit script;
description = "Reconfigure the system from EC2 userdata on startup";
-
wantedBy = [ "sshd.service" ];
-
before = [ "sshd.service" ];
-
after = [ "network-online.target" ];
+
wantedBy = [ "multi-user.target" ];
+
after = [ "multi-user.target" ];
requires = [ "network-online.target" ];
restartIfChanged = false;
+19 -2
nixos/tests/ec2.nix
···
# access. Mostly copied from
# modules/profiles/installation-device.nix.
system.extraDependencies =
-
[ pkgs.stdenv pkgs.busybox pkgs.perlPackages.ArchiveCpio
-
pkgs.unionfs-fuse pkgs.mkinitcpio-nfs-utils
+
with pkgs; [
+
stdenv busybox perlPackages.ArchiveCpio unionfs-fuse mkinitcpio-nfs-utils
+
+
# These are used in the configure-from-userdata tests for EC2. Httpd and valgrind are requested
+
# directly by the configuration we set, and libxslt.bin is used indirectly as a build dependency
+
# of the derivation for dbus configuration files.
+
apacheHttpd valgrind.doc libxslt.bin
];
}
];
···
# ### http://nixos.org/channels/nixos-unstable nixos
userData = ''
+
{ pkgs, ... }:
+
{
imports = [
<nixpkgs/nixos/modules/virtualisation/amazon-image.nix>
···
environment.etc.testFile = {
text = "whoa";
};
+
+
services.httpd = {
+
enable = true;
+
adminAddr = "test@example.org";
+
documentRoot = "${pkgs.valgrind.doc}/share/doc/valgrind/html";
+
};
+
networking.firewall.allowedTCPPorts = [ 80 ];
}
'';
script = ''
$machine->start;
$machine->waitForFile("/etc/testFile");
$machine->succeed("cat /etc/testFile | grep -q 'whoa'");
+
+
$machine->waitForUnit("httpd.service");
+
$machine->succeed("curl http://localhost | grep Valgrind");
'';
};
}