pinwheel: Hibernate instead of suspend when the battery is low
Adds a swap file to hold the hibernation image. The low battery timer and UPower's critical action now hibernate, and SUPER+SHIFT+x uses `suspend-then-hibernate` so a suspended laptop hibernates before the battery runs out.
This commit is contained in:
2 files changed
+16
-8
No files matched your search
@@ -27,17 +27,25 @@ in
|
||||
description = "Notify low battery at this level";
|
||||
};
|
||||
|
||||
suspendCapacity = lib.mkOption {
|
||||
hibernateCapacity = lib.mkOption {
|
||||
default = 10;
|
||||
description = "Warn at this level and then suspend if power is not plugged in";
|
||||
description = "Warn at this level and then hibernate if power is not plugged in";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
swapDevices = lib.mkIf enabled [
|
||||
{
|
||||
device = "/var/lib/swapfile";
|
||||
size = 64 * 1024; # MiB
|
||||
}
|
||||
];
|
||||
|
||||
services = lib.mkIf enabled {
|
||||
upower = {
|
||||
enable = true;
|
||||
criticalPowerAction = "Hibernate";
|
||||
};
|
||||
|
||||
logind.settings.Login = {
|
||||
@@ -62,7 +70,7 @@ in
|
||||
timers = {
|
||||
"monitor-low-battery" = {
|
||||
unitConfig = {
|
||||
Description = "monitors battery level and suspends computer if battery is low";
|
||||
Description = "monitors battery level and hibernates computer if battery is low";
|
||||
};
|
||||
|
||||
timerConfig = {
|
||||
@@ -78,7 +86,7 @@ in
|
||||
services = {
|
||||
"monitor-low-battery" = {
|
||||
unitConfig = {
|
||||
Description = "monitors battery level and suspends computer if battery is low";
|
||||
Description = "monitors battery level and hibernates computer if battery is low";
|
||||
};
|
||||
|
||||
serviceConfig = {
|
||||
@@ -105,13 +113,13 @@ in
|
||||
notify-send --expire-time=0 --urgency=critical "Battery Low"
|
||||
fi
|
||||
|
||||
if [[ $BATTERY_CAPACITY -le ${builtins.toString lowbat.suspendCapacity} && $BATTERY_STATUS = "Discharging" ]]; then
|
||||
notify-send --expire-time=0 --urgency=critical "Battery Critically Low" "Suspending in 60 seconds if power is not plugged in"
|
||||
if [[ $BATTERY_CAPACITY -le ${builtins.toString lowbat.hibernateCapacity} && $BATTERY_STATUS = "Discharging" ]]; then
|
||||
notify-send --expire-time=0 --urgency=critical "Battery Critically Low" "Hibernating in 60 seconds if power is not plugged in"
|
||||
sleep 60s
|
||||
|
||||
BATTERY_STATUS=$(cat /sys/class/power_supply/${lowbat.battery}/status)
|
||||
if [[ $BATTERY_STATUS = "Discharging" ]]; then
|
||||
${pause-music}; ${pkgs.hyprlock}/bin/hyprlock & sleep 0.5; systemctl suspend
|
||||
${pause-music}; ${pkgs.hyprlock}/bin/hyprlock & sleep 0.5; systemctl hibernate
|
||||
fi
|
||||
fi
|
||||
'';
|
||||
|
||||
Reference in new issue
Block a user