diff options
author | lassulus <lass@aidsballs.de> | 2016-06-18 21:51:45 +0200 |
---|---|---|
committer | lassulus <lass@aidsballs.de> | 2016-06-18 21:51:45 +0200 |
commit | 1b238cf556064996b9db9b4a86c232228a0e9114 (patch) | |
tree | 16a8ddc0e014d864d84b7f6831e685a24286573a /lass/3modules/power-action.nix | |
parent | 6e2cbdfb734d24a5c4dfb37b9ccc0b093c07c1f6 (diff) |
l 3 power-action: add charging check
Diffstat (limited to 'lass/3modules/power-action.nix')
-rw-r--r-- | lass/3modules/power-action.nix | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lass/3modules/power-action.nix b/lass/3modules/power-action.nix index 631e651ff..06a316270 100644 --- a/lass/3modules/power-action.nix +++ b/lass/3modules/power-action.nix @@ -25,6 +25,16 @@ let plans = mkOption { type = with types; attrsOf (submodule { options = { + charging = mkOption { + type = nullOr bool; + default = null; + description = '' + check for charging status. + null = don't care + true = only if system is charging + false = only if system is discharging + ''; + }; upperLimit = mkOption { type = int; }; @@ -53,15 +63,31 @@ let }; startScript = pkgs.writeDash "power-action" '' + set -euf + power="$(${powerlvl})" + 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" ]'' + ; writeRule = _: plan: - "if [ $power -ge ${toString plan.lowerLimit} ] && [ $power -le ${toString plan.upperLimit} ]; then ${plan.action}; fi"; + "if [ $power -ge ${toString plan.lowerLimit} ] && [ $power -le ${toString plan.upperLimit} ] ${charging_check plan}; then ${plan.action}; fi"; powerlvl = pkgs.writeDash "powerlvl" '' cat /sys/class/power_supply/BAT0/capacity ''; + state = pkgs.writeDash "state" '' + if [ "$(cat /sys/class/power_supply/BAT0/status)" = "Charging" ] + then echo "true" + else echo "false" + fi + ''; + in out |