1
0
mirror of https://github.com/kmein/niveum synced 2026-03-19 11:31:09 +01:00
This commit is contained in:
2025-12-27 22:22:54 +01:00
parent cb0307e8bf
commit c3db0404b3
139 changed files with 2630 additions and 1976 deletions

View File

@@ -4,7 +4,8 @@
pkgs,
...
}:
with lib; let
with lib;
let
cfg = config.services.power-action;
out = {
@@ -27,7 +28,8 @@ with lib; let
default = "*:0/1";
};
plans = mkOption {
type = with types;
type =
with types;
attrsOf (submodule {
options = {
charging = mkOption {
@@ -71,14 +73,18 @@ with lib; let
state="$(${state})"
${concatStringsSep "\n" (mapAttrsToList writeRule cfg.plans)}
'';
charging_check = plan:
if (plan.charging == null)
then ""
else if plan.charging
then ''&& [ "$state" = "true" ]''
else ''&& ! [ "$state" = "true" ]'';
charging_check =
plan:
if (plan.charging == null) then
""
else if plan.charging then
''&& [ "$state" = "true" ]''
else
''&& ! [ "$state" = "true" ]'';
writeRule = _: plan: "if [ $power -ge ${toString plan.lowerLimit} ] && [ $power -le ${toString plan.upperLimit} ] ${charging_check plan}; then ${plan.action}; fi";
writeRule =
_: plan:
"if [ $power -ge ${toString plan.lowerLimit} ] && [ $power -le ${toString plan.upperLimit} ] ${charging_check plan}; then ${plan.action}; fi";
powerlvl = pkgs.writers.writeDash "powerlvl" ''
cat /sys/class/power_supply/${cfg.battery}/capacity
@@ -91,4 +97,4 @@ with lib; let
fi
'';
in
out
out