niksos/options/desktop/power-supply.nix

37 lines
1.2 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;
inherit (inputs.hyprland.packages.${pkgs.system}) hyprland;
hyprctl = getExe' hyprland "hyprctl";
in {
services.udev.extraRules = let
2024-04-23 12:11:25 +02:00
power_supply = pkgs.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-04-23 12:11:25 +02:00
battery = pkgs.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
}