Merge pull request #168774 from helsinki-systems/feat/systemd-shutdown
nixos/systemd: Properly shut down the system
This commit is contained in:
32
nixos/modules/system/boot/systemd/shutdown.nix
Normal file
32
nixos/modules/system/boot/systemd/shutdown.nix
Normal file
@@ -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
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user