feat(power): suspend-then-hibernate 1h on battery (#115)
All checks were successful
Check / eval (push) Successful in 6m16s

Human decision: 1h delay, battery only, Preferences enable/disable.
Wire systemd suspend-then-hibernate + HibernateDelaySec=1h +
HibernateOnACPower=false when settings.power.suspendThenHibernate is on
and boot.resumeDevice is set. Lid: s2h undocked, plain suspend on AC.
nomarchy-suspend for hypridle + Power menu (live state). LUKS unlock
before encrypted hibernate so s2h→disk is not double-password.
state-bridges assert the policy; HARDWARE-QUEUE #115 + suggested order.

V1: nix flake check --no-build. V3: bag-carry on hardware.
This commit is contained in:
2026-07-15 12:13:23 +01:00
parent e9dd3d14c5
commit 52d1581131
13 changed files with 304 additions and 51 deletions

View File

@@ -22,6 +22,9 @@ let
in
{
config = lib.mkIf cfg.idle.enable {
# Smart suspend on PATH for manual use; hypridle uses the store path.
home.packages = [ pkgs.nomarchy-suspend ];
programs.hyprlock = {
enable = true;
settings = {
@@ -122,10 +125,15 @@ in
# Suspend only on battery, and sooner than the old fixed 30 min
# (it now only fires unplugged). Plugged in, the machine stays
# up — long builds, media, presentations aren't killed mid-idle.
# nomarchy-suspend (#115): on battery + hibernate wired + toggle
# on → suspend-then-hibernate (1h → disk); else plain suspend.
# Lid close is logind's job (not hypridle): undocked lid still
# suspends (HandleLidSwitch); docked/clamshell lid is ignore
# suspends / s2h (HandleLidSwitch); docked/clamshell lid is ignore
# (HandleLidSwitchDocked — modules/nixos/power.nix, #86).
{ timeout = 900; on-timeout = "${onAc} || systemctl suspend"; }
{
timeout = 900;
on-timeout = "${onAc} || ${lib.getExe pkgs.nomarchy-suspend}";
}
];
};
};

View File

@@ -216,6 +216,18 @@ let
done
return 1
}
# Hibernate path available (logind CanHibernate, or resume= fallback).
# Gates the #115 Preferences row so machines without swap/resume hide it.
can_hibernate() {
local v
v=$(busctl get-property org.freedesktop.login1 \
/org/freedesktop/login1 org.freedesktop.login1.Manager \
CanHibernate 2>/dev/null || true)
case "$v" in
's "yes"') return 0 ;;
esac
grep -qE '(^|[[:space:]])resume=' /proc/cmdline 2>/dev/null
}
urlencode() {
local s="$1" out="" ch i
@@ -304,7 +316,13 @@ let
"$BACK") exec "$0" ;;
*Lock) loginctl lock-session ;;
*Logout) hyprctl dispatch exit ;;
*Suspend) systemctl suspend ;;
*Suspend)
# #115: nomarchy-suspend s2h on battery when enabled; else suspend.
if command -v nomarchy-suspend >/dev/null 2>&1; then
nomarchy-suspend
else
systemctl suspend
fi ;;
*Hibernate)
# zram can't hold a hibernate image; a machine installed with
# swap=0 has no disk swap. Attempt, and if logind rejects it,
@@ -1324,6 +1342,13 @@ ${themeRows}
row "Power profile" preferences-system-power
fi
has_system_battery && row "Battery limit" battery-080
# #115: only offer when hibernate can work (self-gate).
if can_hibernate; then
case "$(nomarchy-state-sync get settings.power.suspendThenHibernate 2>/dev/null)" in
false|False) row "Suspend then hibernate (off)" system-suspend ;;
*) row "Suspend then hibernate (on)" system-suspend ;;
esac
fi
command -v nomarchy-doctor >/dev/null 2>&1 && row "Doctor" utilities-system-monitor
back
} | rofi_menu -show-icons -markup-rows -p Preferences) || exit 0
@@ -1338,6 +1363,7 @@ ${themeRows}
*Printing*) exec "$0" printing-toggle ;;
*"Power profile"*) exec "$0" power-profile ;;
*"Battery limit"*) exec "$0" batterylimit ;;
*"Suspend then hibernate"*) exec "$0" suspend-then-hibernate-toggle ;;
*Doctor*) exec "$0" doctor ;;
esac ;;
@@ -1368,6 +1394,25 @@ ${themeRows}
echo
printf 'Enter to close.'; read -r _" ;;
suspend-then-hibernate-toggle)
# #115: settings.power.suspendThenHibernate logind + sleep.conf.
# hypridle/Power menu pick it up live via nomarchy-suspend; lid policy
# needs the system rebuild (same shape as Bluetooth package).
can_hibernate \
|| { notify-send "Suspend then hibernate" \
"Hibernate is not available on this machine (no resume/swap path)."; exit 0; }
case "$(nomarchy-state-sync get settings.power.suspendThenHibernate 2>/dev/null)" in
false|False) new=true; label=On ;;
*) new=false; label=Off ;;
esac
exec ${cfg.terminal} -e sh -c "
nomarchy-state-sync --quiet set settings.power.suspendThenHibernate $new --no-switch
echo \"Suspend then hibernate $label (1h on battery; system rebuild)\"
echo
nomarchy-rebuild
echo
printf 'Enter to close.'; read -r _" ;;
printing-toggle)
case "$(nomarchy-state-sync get settings.printing.enable 2>/dev/null)" in
true|True) new=false; label=Off ;;
@@ -1485,7 +1530,7 @@ ${themeRows}
esac ;;
*)
echo "usage: nomarchy-menu [lookfeel|tools|system|system-connectivity|system-devices|system-preferences|recovery|power|power-profile|powermgmt|batterylimit|theme|clipboard|calc|files|emoji|web|network|bluetooth|airplane|audio|display|display-profile|keyboard|printers|capture|colorpicker|keybinds|ask|dnd|nightlight|autotimezone|autologin|autocommit|vpn|snapshot|doctor|firmware|fingerprint|rollback|whatchanged|blur|gaps|updates-toggle|bluetooth-package|printing-toggle]" >&2
echo "usage: nomarchy-menu [lookfeel|tools|system|system-connectivity|system-devices|system-preferences|recovery|power|power-profile|powermgmt|batterylimit|theme|clipboard|calc|files|emoji|web|network|bluetooth|airplane|audio|display|display-profile|keyboard|printers|capture|colorpicker|keybinds|ask|dnd|nightlight|autotimezone|autologin|autocommit|vpn|snapshot|doctor|firmware|fingerprint|rollback|whatchanged|blur|gaps|updates-toggle|bluetooth-package|printing-toggle|suspend-then-hibernate-toggle]" >&2
exit 64 ;;
esac
'';