1
1
Fork 0

Compare commits

...

2 commits

Author SHA1 Message Date
d854f9bd80
power-profiles-daemon: add profile switch at boot/resume
Signed-off-by: Myned <dev@bjork.tech>
2025-01-29 06:23:30 -06:00
c656090494
power: switch to hybrid-sleep
Signed-off-by: Myned <dev@bjork.tech>
2025-01-29 06:22:56 -06:00
5 changed files with 23 additions and 7 deletions

View file

@ -37,7 +37,7 @@
#?? sudo btrfs inspect-internal map-swapfile -r /swap/swapfile
"resume_offset=533760"
# Fix battery drain with suspend-then-hibernate
# Fix battery drain with suspend
# https://wiki.archlinux.org/title/Framework_Laptop_13#Suspend-then-hibernate_on_AMD_version
"rtc_cmos.use_acpi_alarm=1"

View file

@ -46,7 +46,7 @@ in {
{
timeout = 60 * 60; # Seconds
on-timeout = "${pw-cli} info all | ${grep} running || ${systemctl} suspend-then-hibernate"; # Suspend if no audio
on-timeout = "${pw-cli} info all | ${grep} running || ${systemctl} hybrid-sleep"; # Suspend if no audio
}
];
};

View file

@ -10,7 +10,7 @@ in {
config = mkIf cfg.enable {
services.logind = {
lidSwitch = "suspend-then-hibernate"; # Laptop lid switch
lidSwitch = "hybrid-sleep"; # Laptop lid switch
};
};
}

View file

@ -5,6 +5,7 @@
...
}:
with lib; let
grep = "${pkgs.gnugrep}/bin/grep";
powerprofilesctl = "${pkgs.power-profiles-daemon}/bin/powerprofilesctl";
cfg = config.custom.services.power-profiles-daemon;
@ -28,12 +29,27 @@ in {
# Switch to power-saver mode when on battery
# https://wiki.archlinux.org/title/Power_management#Using_a_script_and_an_udev_rule
udev.extraRules = mkIf cfg.auto ''
# Battery
SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="${powerprofilesctl} set power-saver"
# AC
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="${powerprofilesctl} set balanced"
# Battery
SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="${powerprofilesctl} set power-saver"
'';
};
# Set power profile at boot/resume
powerManagement = let
set_profile = toString (pkgs.writeShellScript "set_profile" ''
if ${grep} 1 /sys/class/power_supply/*/online; then
# AC
${powerprofilesctl} set balanced
else
# Battery
${powerprofilesctl} set power-saver
fi
'');
in {
powerUpCommands = set_profile;
resumeCommands = set_profile;
};
};
}

View file

@ -61,7 +61,7 @@ in {
# https://github.com/NixOS/nixpkgs/pull/259196
# Suspend system
{
command = "${systemctl} suspend-then-hibernate";
command = "${systemctl} hybrid-sleep";
timeout = 60 * 60; # Minutes * 60
}
];