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
@@ -93,7 +93,7 @@ in
|
|||||||
_args = [
|
_args = [
|
||||||
"SUPER + SHIFT + x"
|
"SUPER + SHIFT + x"
|
||||||
(lib.generators.mkLuaInline
|
(lib.generators.mkLuaInline
|
||||||
''hl.dsp.exec_cmd("${pause-music}; ${pkgs.hyprlock}/bin/hyprlock & sleep 0.5; systemctl suspend")''
|
''hl.dsp.exec_cmd("${pause-music}; ${pkgs.hyprlock}/bin/hyprlock & sleep 0.5; systemctl suspend-then-hibernate")''
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,17 +27,25 @@ in
|
|||||||
description = "Notify low battery at this level";
|
description = "Notify low battery at this level";
|
||||||
};
|
};
|
||||||
|
|
||||||
suspendCapacity = lib.mkOption {
|
hibernateCapacity = lib.mkOption {
|
||||||
default = 10;
|
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 = {
|
config = {
|
||||||
|
swapDevices = lib.mkIf enabled [
|
||||||
|
{
|
||||||
|
device = "/var/lib/swapfile";
|
||||||
|
size = 64 * 1024; # MiB
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
services = lib.mkIf enabled {
|
services = lib.mkIf enabled {
|
||||||
upower = {
|
upower = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
criticalPowerAction = "Hibernate";
|
||||||
};
|
};
|
||||||
|
|
||||||
logind.settings.Login = {
|
logind.settings.Login = {
|
||||||
@@ -62,7 +70,7 @@ in
|
|||||||
timers = {
|
timers = {
|
||||||
"monitor-low-battery" = {
|
"monitor-low-battery" = {
|
||||||
unitConfig = {
|
unitConfig = {
|
||||||
Description = "monitors battery level and suspends computer if battery is low";
|
Description = "monitors battery level and hibernates computer if battery is low";
|
||||||
};
|
};
|
||||||
|
|
||||||
timerConfig = {
|
timerConfig = {
|
||||||
@@ -78,7 +86,7 @@ in
|
|||||||
services = {
|
services = {
|
||||||
"monitor-low-battery" = {
|
"monitor-low-battery" = {
|
||||||
unitConfig = {
|
unitConfig = {
|
||||||
Description = "monitors battery level and suspends computer if battery is low";
|
Description = "monitors battery level and hibernates computer if battery is low";
|
||||||
};
|
};
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
@@ -105,13 +113,13 @@ in
|
|||||||
notify-send --expire-time=0 --urgency=critical "Battery Low"
|
notify-send --expire-time=0 --urgency=critical "Battery Low"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $BATTERY_CAPACITY -le ${builtins.toString lowbat.suspendCapacity} && $BATTERY_STATUS = "Discharging" ]]; then
|
if [[ $BATTERY_CAPACITY -le ${builtins.toString lowbat.hibernateCapacity} && $BATTERY_STATUS = "Discharging" ]]; then
|
||||||
notify-send --expire-time=0 --urgency=critical "Battery Critically Low" "Suspending in 60 seconds if power is not plugged in"
|
notify-send --expire-time=0 --urgency=critical "Battery Critically Low" "Hibernating in 60 seconds if power is not plugged in"
|
||||||
sleep 60s
|
sleep 60s
|
||||||
|
|
||||||
BATTERY_STATUS=$(cat /sys/class/power_supply/${lowbat.battery}/status)
|
BATTERY_STATUS=$(cat /sys/class/power_supply/${lowbat.battery}/status)
|
||||||
if [[ $BATTERY_STATUS = "Discharging" ]]; then
|
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
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|||||||
Reference in new issue
Block a user