modules: Added suspend-then-hibernate.nix to all laptops
This commit is contained in:
parent
2b98230833
commit
b58a158f09
38
modules/sus-then-hib.nix
Normal file
38
modules/sus-then-hib.nix
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
{ config, pkgs, ... }: let
|
||||||
|
hibernateEnvironment = {
|
||||||
|
HIBERNATE_SECONDS = "3600";
|
||||||
|
HIBERNATE_LOCK = "/var/run/autohibernate.lock";
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
systemd.services."awake-after-suspend-for-a-time" = {
|
||||||
|
description = "Sets up the suspend so that it'll wake for hibernation";
|
||||||
|
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";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
../modules/bluetooth.nix
|
../modules/bluetooth.nix
|
||||||
../modules/networkmanager.nix
|
../modules/networkmanager.nix
|
||||||
../modules/tlp.nix
|
../modules/tlp.nix
|
||||||
|
../modules/sus-then-hib.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue