niksos/hosts/common/optional/power-supply.nix
2024-09-01 20:33:38 +02:00

36 lines
1.3 KiB
Nix

{
config,
inputs,
lib,
pkgs,
...
}: let
inherit (lib.meta) getExe getExe';
asusctl = getExe' config.services.asusd.package "asusctl";
supergfxctl = getExe' config.services.asusd.package "supergfxctl";
cpupower = getExe config.boot.kernelPackages.cpupower;
hyprctl = getExe' inputs.hyprland.packages.${pkgs.system}.hyprland "hyprctl";
inherit (pkgs) writeShellScript;
in {
services.udev.extraRules = let
power_supply = writeShellScript "on_power_supply" ''
${asusctl} profile -P Performance
#${supergfxctl} -m Hybrid
${cpupower} frequency-set -g performance
${hyprctl} keyword decoration:blur:enabled true
${hyprctl} keyword animations:enabled true
'';
battery = writeShellScript "on_battery" ''
${asusctl} profile -P Quiet
#${supergfxctl} -m Integrated
${cpupower} frequency-set -g powersave
${hyprctl} keyword decoration:blur:enabled false
${hyprctl} keyword animations:enabled false
'';
in ''
SUBSYSTEM=="power_supply",ENV{POWER_SUPPLY_ONLINE}=="1",RUN+="${power_supply}"
SUBSYSTEM=="power_supply",ENV{POWER_SUPPLY_ONLINE}=="0",RUN+="${battery}"
'';
}