1
1
Fork 0

power-profiles-daemon: add profile switch at boot/resume

Signed-off-by: Myned <dev@bjork.tech>
This commit is contained in:
Myned 2025-01-29 06:23:30 -06:00
parent c656090494
commit d854f9bd80
Signed by: Myned
GPG key ID: C7224454F7881A34

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;
};
};
}