summaryrefslogtreecommitdiffstats
path: root/makefu/2configs
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2016-08-02 11:50:16 +0200
committermakefu <github@syntax-fehler.de>2016-08-02 11:50:16 +0200
commit278e34c393988b3e039c7e47bbb73eb8adb978f8 (patch)
tree96530820daf147c1a163052624c5b93abfa681fb /makefu/2configs
parente215b30483a4275ac831c6def9c27b004d4d6887 (diff)
m 2 main-laptop: add power-action
Diffstat (limited to 'makefu/2configs')
-rw-r--r--makefu/2configs/main-laptop.nix38
1 files changed, 38 insertions, 0 deletions
diff --git a/makefu/2configs/main-laptop.nix b/makefu/2configs/main-laptop.nix
index 3cc91b630..92cc1fc43 100644
--- a/makefu/2configs/main-laptop.nix
+++ b/makefu/2configs/main-laptop.nix
@@ -16,6 +16,44 @@ with config.krebs.lib;
users.users.${config.krebs.build.user.name}.extraGroups = [ "dialout" ];
+ krebs.power-action = let
+ speak = "${pkgs.espeak}/bin/espeak";
+ whisper = text: ''${pkgs.espeak}/bin/espeak -v +whisper -s 110 "${text}"'';
+ note = "${pkgs.libnotify}/bin/notify-send";
+ in {
+ enable = true;
+ plans.low-battery = {
+ upperLimit = 25;
+ lowerLimit = 15;
+ charging = false;
+ action = whisper "power level low, please plug me in";
+ };
+ plans.nag-harder = {
+ upperLimit = 15;
+ lowerLimit = 5;
+ action = pkgs.writeDash "crit-speak" ''
+ ${whisper "Power level critical, do something"}
+ ${note} Battery -u critical -t 600000 "Power level critical, do something!"
+ '';
+ };
+ plans.last-chance = {
+ upperLimit = 5;
+ lowerLimit = 3;
+ charging = false;
+ action = pkgs.writeDash "suspend-wrapper" ''
+ ${note} Battery -u crit "You've had your chance, suspend in 5 seconds"
+ ${concatMapStringsSep "\n" (i: ''
+ ${note} -u critical -t 1000 ${toString i}
+ ${speak} ${toString i} &
+ sleep 1
+ '')
+ [ 5 4 3 2 1 ]}
+ /var/setuid-wrappers/sudo ${pkgs.systemd}/bin/systemctl suspend
+ '';
+ };
+ };
+ users.users.power-action.extraGroups = [ "audio" ];
+ security.sudo.extraConfig = "${config.krebs.power-action.user.name} ALL= (root) NOPASSWD: ${pkgs.systemd}/bin/systemctl suspend";
services.redshift = {
enable = true;