10 cfg = config.systemd.shutdownRamfs;
12 ramfsContents = pkgs.writeText "shutdown-ramfs-contents.json" (builtins.toJSON cfg.storePaths);
16 options.systemd.shutdownRamfs = {
17 enable = lib.mkEnableOption "pivoting back to an initramfs for shutdown" // {
20 contents = lib.mkOption {
21 description = "Set of files that have to be linked into the shutdown ramfs";
22 example = lib.literalExpression ''
24 "/lib/systemd/system-shutdown/zpool-sync-shutdown".source = writeShellScript "zpool" "exec ''${zfs}/bin/zpool sync"
27 type = utils.systemdUtils.types.initrdContents;
30 storePaths = lib.mkOption {
32 Store paths to copy into the shutdown ramfs as well.
34 type = utils.systemdUtils.types.initrdStorePath;
39 config = lib.mkIf cfg.enable {
40 systemd.shutdownRamfs.contents = {
41 "/shutdown".source = "${config.systemd.package}/lib/systemd/systemd-shutdown";
42 "/etc/initrd-release".source = config.environment.etc.os-release.source;
43 "/etc/os-release".source = config.environment.etc.os-release.source;
45 systemd.shutdownRamfs.storePaths = [
47 "${pkgs.coreutils}/bin"
48 ] ++ map (c: builtins.removeAttrs c [ "text" ]) (builtins.attrValues cfg.contents);
53 where = "/run/initramfs";
58 systemd.services.generate-shutdown-ramfs = {
59 description = "Generate shutdown ramfs";
60 wantedBy = [ "shutdown.target" ];
61 before = [ "shutdown.target" ];
63 DefaultDependencies = false;
64 RequiresMountsFor = "/run/initramfs";
65 ConditionFileIsExecutable = [
66 "!/run/initramfs/shutdown"
72 ProtectSystem = "strict";
73 ReadWritePaths = "/run/initramfs";
74 ExecStart = "${pkgs.makeInitrdNGTool}/bin/make-initrd-ng ${ramfsContents} /run/initramfs";