modules/sus-then-hib: Switch to systemds suspend-then-hibernate
This commit is contained in:
parent
1987cd3c83
commit
78226909f9
|
@ -1,38 +1,11 @@
|
||||||
{ config, pkgs, ... }: let
|
{ config, pkgs, ... }:
|
||||||
hibernateEnvironment = {
|
{
|
||||||
HIBERNATE_SECONDS = "3600";
|
systemd.sleep.extraConfig = "HibernateDelaySec=1h";
|
||||||
HIBERNATE_LOCK = "/var/run/autohibernate.lock";
|
|
||||||
};
|
services.logind = {
|
||||||
in {
|
lidSwitch = "suspend-then-hibernate";
|
||||||
systemd.services."awake-after-suspend-for-a-time" = {
|
suspendKey = "suspend-then-hibernate";
|
||||||
description = "Sets up the suspend so that it'll wake for hibernation";
|
powerKey = "suspend-then-hibernate";
|
||||||
wantedBy = [ "suspend.target" ];
|
|
||||||
before = [ "systemd-suspend.service" ];
|
|
||||||
environment = hibernateEnvironment;
|
|
||||||
script = ''
|
|
||||||
curtime=$(date +%s)
|
|
||||||
echo "$curtime $1" >> /tmp/autohibernate.log
|
|
||||||
echo "$curtime" > $HIBERNATE_LOCK
|
|
||||||
${pkgs.utillinux}/bin/rtcwake -m no -s $HIBERNATE_SECONDS
|
|
||||||
'';
|
|
||||||
serviceConfig.Type = "simple";
|
|
||||||
};
|
|
||||||
systemd.services."hibernate-after-recovery" = {
|
|
||||||
description = "Hibernates after a suspend recovery due to timeout";
|
|
||||||
wantedBy = [ "suspend.target" ];
|
|
||||||
after = [ "systemd-suspend.service" ];
|
|
||||||
environment = hibernateEnvironment;
|
|
||||||
script = ''
|
|
||||||
curtime=$(date +%s)
|
|
||||||
sustime=$(cat $HIBERNATE_LOCK)
|
|
||||||
rm $HIBERNATE_LOCK
|
|
||||||
if [ $(($curtime - $sustime)) -ge $(($HIBERNATE_SECONDS - 5)) ] ; then
|
|
||||||
systemctl hibernate
|
|
||||||
else
|
|
||||||
${pkgs.utillinux}/bin/rtcwake -m no -s 1
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
serviceConfig.Type = "simple";
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue