summaryrefslogtreecommitdiffstats
path: root/makefu/2configs/main-laptop.nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2016-08-02 20:58:42 +0200
committertv <tv@krebsco.de>2016-08-02 20:58:42 +0200
commite6aef09ad41cd55d716b8ee276ebd774b95d8ecb (patch)
tree6d8d5cce976f3843ab196367e82fec56f0798838 /makefu/2configs/main-laptop.nix
parent0928cc03a6191640c66c9122159994855527faef (diff)
parentb197949ab83ee3ee87b5774e0fc7c8d0123a6708 (diff)
Merge remote-tracking branch 'gum/master'
Diffstat (limited to 'makefu/2configs/main-laptop.nix')
-rw-r--r--makefu/2configs/main-laptop.nix51
1 files changed, 50 insertions, 1 deletions
diff --git a/makefu/2configs/main-laptop.nix b/makefu/2configs/main-laptop.nix
index 3cc91b630..9d5b06f70 100644
--- a/makefu/2configs/main-laptop.nix
+++ b/makefu/2configs/main-laptop.nix
@@ -6,7 +6,10 @@
# TODO split generic desktop stuff and laptop-specifics like lidswitching
with config.krebs.lib;
-{
+let
+ window-manager = "awesome";
+ user = config.krebs.build.user.name;
+in {
imports = [
./base-gui.nix
./fetchWallpaper.nix
@@ -16,6 +19,52 @@ with config.krebs.lib;
users.users.${config.krebs.build.user.name}.extraGroups = [ "dialout" ];
+ krebs.power-action = let
+ #speak = "XDG_RUNTIME_DIR=/run/user/$(id -u) ${pkgs.espeak}/bin/espeak"; # when run as user
+ speak = "${pkgs.espeak}/bin/espeak"; # systemwide pulse
+ whisper = text: ''${speak} -v +whisper -s 110 "${text}"'';
+
+ note = pkgs.writeDash "note-as-user" ''
+ eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(${pkgs.procps}/bin/pgrep -u ${user} ${window-manager})/environ)"
+ ${pkgs.libnotify}/bin/notify-send "$@";
+ '';
+ in {
+ enable = true;
+ inherit user;
+ plans.low-battery = {
+ upperLimit = 25;
+ lowerLimit = 15;
+ charging = false;
+ action = pkgs.writeDash "low-speak" ''
+ ${whisper "power level low, please plug me in"}
+ '';
+ };
+ plans.nag-harder = {
+ upperLimit = 15;
+ lowerLimit = 5;
+ charging = false;
+ action = pkgs.writeDash "crit-speak" ''
+ ${note} Battery -u critical -t 60000 "Power level critical, do something!"
+ ${whisper "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
+ '';
+ };
+ };
+ security.sudo.extraConfig = "${config.krebs.power-action.user} ALL= (root) NOPASSWD: ${pkgs.systemd}/bin/systemctl suspend";
services.redshift = {
enable = true;