{ config, lib, ... }: let cfg = config.nomarchy.system.hibernation; in { config = lib.mkIf cfg.enable { # Wait this long after suspend before hibernating, and use the same # delay as the idle-action timeout so the two paths agree. systemd.sleep.extraConfig = '' HibernateDelaySec=${toString (cfg.idleMinutes * 60)} ''; services.logind = { settings.Login = { HandleLidSwitch = lib.mkDefault "suspend-then-hibernate"; HandleLidSwitchExternalPower = lib.mkDefault "suspend"; HandlePowerKey = "hibernate"; IdleAction = "suspend-then-hibernate"; IdleActionSec = toString (cfg.idleMinutes * 60); }; }; }; }