2022-04-24 14:47:28 -04:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
systemdStage1 ? false,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
msg = "Shutting down NixOS";
|
|
|
|
in
|
|
|
|
{
|
2022-04-15 11:23:02 +01:00
|
|
|
name = "systemd-shutdown";
|
|
|
|
meta = with pkgs.lib.maintainers; {
|
|
|
|
maintainers = [ das_j ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes.machine = {
|
|
|
|
imports = [ ../modules/profiles/minimal.nix ];
|
2022-04-24 14:47:28 -04:00
|
|
|
systemd.shutdownRamfs.contents."/etc/systemd/system-shutdown/shutdown-message".source =
|
|
|
|
pkgs.writeShellScript "shutdown-message" ''
|
2025-04-04 18:15:12 -04:00
|
|
|
echo "${msg}" > /dev/kmsg
|
2022-04-24 14:47:28 -04:00
|
|
|
'';
|
2023-02-23 19:42:45 -05:00
|
|
|
boot.initrd.systemd.enable = systemdStage1;
|
2022-04-15 11:23:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2025-04-02 15:56:28 -04:00
|
|
|
# Check that 'generate-shutdown-ramfs.service' is started
|
|
|
|
# automatically and that 'systemd-shutdown' runs our script.
|
2022-04-15 11:23:02 +01:00
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
# .shutdown() would wait for the machine to power off
|
|
|
|
machine.succeed("systemctl poweroff")
|
|
|
|
# Message printed by systemd-shutdown
|
2022-04-24 14:47:28 -04:00
|
|
|
machine.wait_for_console_text("Unmounting '/oldroot'")
|
|
|
|
machine.wait_for_console_text("${msg}")
|
2022-04-15 11:23:02 +01:00
|
|
|
# Don't try to sync filesystems
|
2023-07-28 18:52:48 -04:00
|
|
|
machine.wait_for_shutdown()
|
2025-04-02 15:56:28 -04:00
|
|
|
|
|
|
|
# In a separate boot, start 'generate-shutdown-ramfs.service'
|
|
|
|
# manually in order to check the permissions on '/run/initramfs'.
|
|
|
|
machine.systemctl("start generate-shutdown-ramfs.service")
|
|
|
|
stat = machine.succeed("stat --printf=%a:%u:%g /run/initramfs")
|
|
|
|
assert stat == "700:0:0", f"Improper permissions on /run/initramfs: {stat}"
|
2022-04-15 11:23:02 +01:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|