power-profiles-daemon: add profile switch at boot/resume
Signed-off-by: Myned <dev@bjork.tech>
This commit is contained in:
parent
c656090494
commit
d854f9bd80
1 changed files with 19 additions and 3 deletions
|
@ -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;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue