diff --git a/options/custom/services/power-profiles-daemon.nix b/options/custom/services/power-profiles-daemon.nix index 1d6a870..785552b 100644 --- a/options/custom/services/power-profiles-daemon.nix +++ b/options/custom/services/power-profiles-daemon.nix @@ -1,12 +1,18 @@ { config, lib, + pkgs, ... }: with lib; let + powerprofilesctl = "${pkgs.power-profiles-daemon}/bin/powerprofilesctl"; + cfg = config.custom.services.power-profiles-daemon; 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 { # https://gitlab.freedesktop.org/upower/power-profiles-daemon @@ -14,7 +20,20 @@ in { #?? powerprofilesctl set services = { 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" + ''; }; }; }