niksos/hosts/common/optional/power-supply.nix

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.stdenv.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}"
'';
}