3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/nixos/modules/system/boot/systemd/shutdown.nix
2022-04-16 21:17:36 +01:00

33 lines
913 B
Nix

{ 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
'';
};
};
}