nixos/modules/hardware/action-on-low-power/default.nix
Felix Buehler c8fc9152fd
Some checks are pending
/ Build Nix targets (push) Waiting to run
hardware/action-on-low-power: init
2025-09-02 00:06:55 +02:00

45 lines
972 B
Nix

# low power action
{
config,
lib,
options,
pkgs,
...
}:
let
cfg = config.my.hardware.action-on-low-power;
in
{
options.my.hardware.action-on-low-power = {
enable = lib.mkEnableOption "action on low power";
action = lib.mkOption {
type = lib.types.enum [
"hibernate"
"hybrid-sleep"
"poweroff"
"sleep"
"suspend-then-hibernate"
"suspend"
];
default = "sleep";
description = ''
Action to take when power is low.
'';
};
powerInPercent = lib.mkOption {
type = lib.types.int;
default = 10;
description = ''
Power percentage threshold to trigger the action.
'';
};
};
config = lib.mkIf cfg.enable {
services.udev.extraRules = ''
SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="${toString cfg.powerInPercent}", RUN+="${config.systemd.package}/bin/systemctl ${cfg.action}"
'';
};
}