1
1
Fork 0

power-profiles-daemon: add profile switch udev rules on battery

Signed-off-by: Myned <dev@bjork.tech>
This commit is contained in:
Myned 2024-12-21 13:29:14 -05:00
parent 9839699d2d
commit dfd22068bd
Signed by: myned
GPG key ID: C7224454F7881A34

View file

@ -1,12 +1,18 @@
{ {
config, config,
lib, lib,
pkgs,
... ...
}: }:
with lib; let with lib; let
powerprofilesctl = "${pkgs.power-profiles-daemon}/bin/powerprofilesctl";
cfg = config.custom.services.power-profiles-daemon; cfg = config.custom.services.power-profiles-daemon;
in { in {
options.custom.services.power-profiles-daemon.enable = mkOption {default = false;}; options.custom.services.power-profiles-daemon = {
enable = mkOption {default = false;};
auto = mkOption {default = true;};
};
config = mkIf cfg.enable { config = mkIf cfg.enable {
# https://gitlab.freedesktop.org/upower/power-profiles-daemon # https://gitlab.freedesktop.org/upower/power-profiles-daemon
@ -14,7 +20,20 @@ in {
#?? powerprofilesctl set <performance|balanced|power-saver> #?? powerprofilesctl set <performance|balanced|power-saver>
services = { services = {
power-profiles-daemon.enable = true; power-profiles-daemon.enable = true;
tlp.enable = false; # Conflicts with PPD
#!! Conflicts with power-profiles-daemon
auto-cpufreq.enable = false;
tlp.enable = false;
# 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"
'';
}; };
}; };
} }