nixos/boot: add postResumeCommands option

Adds a postResumeCommands option to the initramfs to allow inserting
code to execute after the device has attempted to resume, and before
filesystems are mounted. This allows to inject code for operations like
wiping the rootfs on boot; if those were instead put in
postDeviceCommands, on a hibernated device, they would execute before
the device resumes from hibernation.

Changed files
+12 -1
nixos
modules
system
+2
nixos/modules/system/boot/stage-1-init.sh
···
fi
fi
+
@postResumeCommands@
+
# If we have a path to an iso file, find the iso and link it to /dev/root
if [ -n "$isoPath" ]; then
mkdir -p /findiso
+9 -1
nixos/modules/system/boot/stage-1.nix
···
inherit (config.system.build) earlyMountScript;
inherit (config.boot.initrd) checkJournalingFS verbose
-
preLVMCommands preDeviceCommands postDeviceCommands postMountCommands preFailCommands kernelModules;
+
preLVMCommands preDeviceCommands postDeviceCommands postResumeCommands postMountCommands preFailCommands kernelModules;
resumeDevices = map (sd: if sd ? device then sd.device else "/dev/disk/by-label/${sd.label}")
(filter (sd: hasPrefix "/dev/" sd.device && !sd.randomEncryption.enable
···
Shell commands to be executed immediately after stage 1 of the
boot has loaded kernel modules and created device nodes in
{file}`/dev`.
+
'';
+
};
+
+
boot.initrd.postResumeCommands = mkOption {
+
default = "";
+
type = types.lines;
+
description = lib.mdDoc ''
+
Shell commands to be executed immediately after attempting to resume.
'';
};
+1
nixos/modules/system/boot/systemd/initrd.nix
···
[ "preDeviceCommands" ]
[ "preLVMCommands" ]
[ "postDeviceCommands" ]
+
[ "postResumeCommands" ]
[ "postMountCommands" ]
[ "extraUdevRulesCommands" ]
[ "extraUtilsCommands" ]