From dcc36d1e746d187e6d2f3e057fcd653508c02b33 Mon Sep 17 00:00:00 2001 From: r-vdp Date: Sun, 8 Feb 2026 21:33:33 +0200 Subject: [PATCH 1/3] nixos/power-management: use sleep.target instead of listing all individual sleep targets See https://www.freedesktop.org/software/systemd/man/latest/systemd.special.html#sleep.target --- nixos/modules/config/power-management.nix | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/nixos/modules/config/power-management.nix b/nixos/modules/config/power-management.nix index 6b2253068c0b..b061bbe6b707 100644 --- a/nixos/modules/config/power-management.nix +++ b/nixos/modules/config/power-management.nix @@ -83,12 +83,8 @@ in systemd.services.post-resume = { description = "Post-Resume Actions"; - after = [ - "suspend.target" - "hibernate.target" - "hybrid-sleep.target" - "suspend-then-hibernate.target" - ]; + # Pulled in by post-resume.service above + after = [ "sleep.target" ]; script = '' /run/current-system/systemd/bin/systemctl try-restart --no-block post-resume.target ${cfg.resumeCommands} From 34fd3fe6a21e7564416eff18ca57d9df3a5f7f99 Mon Sep 17 00:00:00 2001 From: r-vdp Date: Sun, 8 Feb 2026 21:34:37 +0200 Subject: [PATCH 2/3] nixos/power-management: run postBootCommands in a systemd service instead of stage2-init.sh This reduces our initrd script slightly, and we never made any clear ordering guarantees about when these commands run anyway. It also removes this as a blocker for nixos-init. --- nixos/modules/config/power-management.nix | 15 +++++++++++++++ nixos/modules/system/activation/nixos-init.nix | 4 ---- nixos/modules/system/boot/stage-2.nix | 1 - 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/nixos/modules/config/power-management.nix b/nixos/modules/config/power-management.nix index b061bbe6b707..5dcfe5bf013c 100644 --- a/nixos/modules/config/power-management.nix +++ b/nixos/modules/config/power-management.nix @@ -81,6 +81,21 @@ in serviceConfig.Type = "oneshot"; }; + systemd.services.post-boot = { + description = "Post-boot Actions"; + # It's not well defined at what point in the bootup sequence this should run + # we should eventually just remove this. + after = [ "multi-user.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + }; + script = '' + ${cfg.powerUpCommands} + ''; + }; + systemd.services.post-resume = { description = "Post-Resume Actions"; # Pulled in by post-resume.service above diff --git a/nixos/modules/system/activation/nixos-init.nix b/nixos/modules/system/activation/nixos-init.nix index 9d5094017c0b..1ab2e546d40a 100644 --- a/nixos/modules/system/activation/nixos-init.nix +++ b/nixos/modules/system/activation/nixos-init.nix @@ -58,10 +58,6 @@ in assertion = config.boot.postBootCommands == ""; message = "nixos-init cannot be used with boot.postBootCommands"; } - { - assertion = config.powerManagement.powerUpCommands == ""; - message = "nixos-init cannot be used with powerManagement.powerUpCommands"; - } ]; }) ]; diff --git a/nixos/modules/system/boot/stage-2.nix b/nixos/modules/system/boot/stage-2.nix index 680f5eed55c0..9b72391c20ac 100644 --- a/nixos/modules/system/boot/stage-2.nix +++ b/nixos/modules/system/boot/stage-2.nix @@ -30,7 +30,6 @@ let ); postBootCommands = pkgs.writeText "local-cmds" '' ${config.boot.postBootCommands} - ${config.powerManagement.powerUpCommands} ''; }; }; From df0b0d2f147e1cad7683aba0545ac8291c2827d1 Mon Sep 17 00:00:00 2001 From: r-vdp Date: Sun, 8 Feb 2026 21:36:13 +0200 Subject: [PATCH 3/3] nixos/power-management: deprecate powerUpCommands Their ordering is ill-defined. Users are better off using an explicit systemd service. --- nixos/modules/config/power-management.nix | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/nixos/modules/config/power-management.nix b/nixos/modules/config/power-management.nix index 5dcfe5bf013c..b5ae488697a2 100644 --- a/nixos/modules/config/power-management.nix +++ b/nixos/modules/config/power-management.nix @@ -62,6 +62,19 @@ in config = lib.mkIf cfg.enable { + warnings = lib.optional (cfg.powerUpCommands != "") '' + powerManagement.powerUpCommands is deprecated due to it having unclear ordering semantics. + It will be removed in NixOS 26.11. + It is recommended to create an explicit systemd oneshot service instead, + that is pulled in at the right time during the boot process. + See https://www.freedesktop.org/software/systemd/man/latest/systemd.special.html + for more information on possible targets that can be used for this. + + If you also want to run this service upon waking up from resume, the recommended + method to do so is described here: + https://www.freedesktop.org/software/systemd/man/latest/systemd.special.html#sleep.target + ''; + systemd.targets.post-resume = { description = "Post-Resume Actions"; requires = [ "post-resume.service" ]; @@ -85,8 +98,8 @@ in description = "Post-boot Actions"; # It's not well defined at what point in the bootup sequence this should run # we should eventually just remove this. - after = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ]; + restartIfChanged = false; serviceConfig = { Type = "oneshot"; RemainAfterExit = true;