Commit 2a4b82c4 authored by Archit Gupta's avatar Archit Gupta
Browse files

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.
parent 85f1ba3e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -498,6 +498,8 @@ if test -e /sys/power/resume -a -e /sys/power/disk; then
    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
Original line number Diff line number Diff line
@@ -316,7 +316,7 @@ let
    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
@@ -524,6 +524,14 @@ in
      '';
    };

    boot.initrd.postResumeCommands = mkOption {
      default = "";
      type = types.lines;
      description = lib.mdDoc ''
        Shell commands to be executed immediately after attempting to resume.
      '';
    };

    boot.initrd.postMountCommands = mkOption {
      default = "";
      type = types.lines;
+1 −0
Original line number Diff line number Diff line
@@ -358,6 +358,7 @@ in {
      [ "preDeviceCommands" ]
      [ "preLVMCommands" ]
      [ "postDeviceCommands" ]
      [ "postResumeCommands" ]
      [ "postMountCommands" ]
      [ "extraUdevRulesCommands" ]
      [ "extraUtilsCommands" ]