at master 1.4 kB view raw
1{ 2 systemdStage1, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 msg = "Shutting down NixOS"; 9in 10{ 11 name = "systemd-shutdown"; 12 meta.maintainers = with lib.maintainers; [ das_j ]; 13 14 _module.args.systemdStage1 = lib.mkDefault false; 15 16 nodes.machine = { 17 imports = [ ../modules/profiles/minimal.nix ]; 18 systemd.shutdownRamfs.contents."/etc/systemd/system-shutdown/shutdown-message".source = 19 pkgs.writeShellScript "shutdown-message" '' 20 echo "${msg}" > /dev/kmsg 21 ''; 22 boot.initrd.systemd.enable = systemdStage1; 23 }; 24 25 testScript = '' 26 # Check that 'generate-shutdown-ramfs.service' is started 27 # automatically and that 'systemd-shutdown' runs our script. 28 machine.wait_for_unit("multi-user.target") 29 # .shutdown() would wait for the machine to power off 30 machine.succeed("systemctl poweroff") 31 # Message printed by systemd-shutdown 32 machine.wait_for_console_text("Unmounting '/oldroot'") 33 machine.wait_for_console_text("${msg}") 34 # Don't try to sync filesystems 35 machine.wait_for_shutdown() 36 37 # In a separate boot, start 'generate-shutdown-ramfs.service' 38 # manually in order to check the permissions on '/run/initramfs'. 39 machine.systemctl("start generate-shutdown-ramfs.service") 40 stat = machine.succeed("stat --printf=%a:%u:%g /run/initramfs") 41 assert stat == "700:0:0", f"Improper permissions on /run/initramfs: {stat}" 42 ''; 43}