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

37 lines
1.3 KiB
Nix
Raw Normal View History

2024-02-15 17:04:34 +01:00
{
config,
inputs,
lib,
2024-02-15 17:04:34 +01:00
pkgs,
...
2024-07-24 18:47:53 +02:00
}: let
inherit (lib.meta) getExe getExe';
2024-02-15 17:04:34 +01:00
2024-07-24 18:47:53 +02:00
asusctl = getExe' config.services.asusd.package "asusctl";
supergfxctl = getExe' config.services.asusd.package "supergfxctl";
cpupower = getExe config.boot.kernelPackages.cpupower;
2024-09-01 20:33:38 +02:00
hyprctl = getExe' inputs.hyprland.packages.${pkgs.system}.hyprland "hyprctl";
2024-07-24 18:47:53 +02:00
2024-08-30 20:41:42 +02:00
inherit (pkgs) writeShellScript;
2024-07-24 18:47:53 +02:00
in {
services.udev.extraRules = let
2024-08-30 20:41:42 +02:00
power_supply = writeShellScript "on_power_supply" ''
${asusctl} profile -P Performance
#${supergfxctl} -m Hybrid
2024-08-30 20:40:34 +02:00
${cpupower} frequency-set -g performance
${hyprctl} keyword decoration:blur:enabled true
${hyprctl} keyword animations:enabled true
2024-02-15 17:04:34 +01:00
'';
2024-08-30 20:41:42 +02:00
battery = writeShellScript "on_battery" ''
${asusctl} profile -P Quiet
#${supergfxctl} -m Integrated
2024-08-30 20:40:34 +02:00
${cpupower} frequency-set -g powersave
${hyprctl} keyword decoration:blur:enabled false
${hyprctl} keyword animations:enabled false
2024-04-23 12:11:25 +02:00
'';
in ''
SUBSYSTEM=="power_supply",ENV{POWER_SUPPLY_ONLINE}=="1",RUN+="${power_supply}"
SUBSYSTEM=="power_supply",ENV{POWER_SUPPLY_ONLINE}=="0",RUN+="${battery}"
'';
2024-02-15 17:04:34 +01:00
}