From 63ad607d46280a7a2571b59226ab6d99bf11e971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Tue, 26 Jan 2021 22:59:57 +0100 Subject: [PATCH] feat: power-action to suspend on low battery --- configs/default.nix | 1 + configs/power-action.nix | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 configs/power-action.nix diff --git a/configs/default.nix b/configs/default.nix index bcae4f1..984e53f 100644 --- a/configs/default.nix +++ b/configs/default.nix @@ -215,6 +215,7 @@ in { ./newsboat.nix ./flameshot-once.nix ./packages + ./power-action.nix ./printing.nix ./wallpaper.nix ./redshift.nix diff --git a/configs/power-action.nix b/configs/power-action.nix new file mode 100644 index 0000000..f6e93a0 --- /dev/null +++ b/configs/power-action.nix @@ -0,0 +1,24 @@ +{ pkgs, config, ... }: +let + suspend = pkgs.writers.writeDash "suspend" "${pkgs.systemd}/bin/systemctl suspend"; +in +{ + imports = [ ]; + + krebs.power-action = { + enable = true; + plans.suspend = { + upperLimit = 3; + lowerLimit = 0; + charging = false; + action = pkgs.writeDash "suspend-wrapper" '' + /run/wrappers/bin/sudo ${suspend} + ''; + }; + user = config.users.users.me.name; + }; + + security.sudo.extraConfig = '' + ${config.krebs.power-action.user} ALL= (root) NOPASSWD: ${suspend} + ''; +}