summary refs log tree commit diff
path: root/nixos/modules/system/boot/systemd/shutdown.nix
blob: 93426931667627e751373f21ce8874e5bb21a23b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
      '';
    };
  };
}