parent
031b95e587
commit
30a00c29c4
@ -0,0 +1,32 @@ |
||||
{ config, lib, ... }: let |
||||
|
||||
cfg = config.boot.systemd.shutdown; |
||||
|
||||
in { |
||||
options.boot.systemd.shutdown = { |
||||
enable = lib.mkEnableOption "pivoting back to an initramfs for shutdown" // { default = true; }; |
||||
}; |
||||
|
||||
config = lib.mkIf cfg.enable { |
||||
systemd.services.generate-shutdown-ramfs = { |
||||
description = "Generate shutdown ramfs"; |
||||
before = [ "shutdown.target" ]; |
||||
unitConfig = { |
||||
DefaultDependencies = false; |
||||
ConditionFileIsExecutable = [ |
||||
"!/run/initramfs/shutdown" |
||||
"/run/current-system/systemd/lib/systemd/systemd-shutdown" |
||||
]; |
||||
}; |
||||
|
||||
serviceConfig.Type = "oneshot"; |
||||
script = '' |
||||
mkdir -p /run/initramfs |
||||
if ! mountpoint -q /run/initramfs; then |
||||
mount -t tmpfs tmpfs /run/initramfs |
||||
fi |
||||
cp /run/current-system/systemd/lib/systemd/systemd-shutdown /run/initramfs/shutdown |
||||
''; |
||||
}; |
||||
}; |
||||
} |
@ -0,0 +1,21 @@ |
||||
import ./make-test-python.nix ({ pkgs, systemdStage1 ? false, ...} : { |
||||
name = "systemd-shutdown"; |
||||
meta = with pkgs.lib.maintainers; { |
||||
maintainers = [ das_j ]; |
||||
}; |
||||
|
||||
nodes.machine = { |
||||
imports = [ ../modules/profiles/minimal.nix ]; |
||||
boot.initrd.systemd.enable = systemdStage1; |
||||
}; |
||||
|
||||
testScript = '' |
||||
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 |
||||
machine.wait_for_console_text("All filesystems, swaps, loop devices, MD devices and DM devices detached.") |
||||
# Don't try to sync filesystems |
||||
machine.booted = False |
||||
''; |
||||
}) |
Loading…
Reference in new issue