niksos/options/desktop/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;
inherit (inputs.hyprland.packages.${pkgs.system}) hyprland;
hyprctl = getExe' hyprland "hyprctl";
in {
services.udev.extraRules = let
power_supply = pkgs.writeShellScript "on_power_supply" ''
${asusctl} profile -P Performance
#${supergfxctl} -m Hybrid
${cpupower}/bin/cpupower frequency-set -g performance
${hyprctl} keyword decoration:blur:enabled true
${hyprctl} keyword animations:enabled true
'';
battery = pkgs.writeShellScript "on_battery" ''
${asusctl} profile -P Quiet
#${supergfxctl} -m Integrated
${cpupower}/bin/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}"
'';
}