From 575a664ee93433b6c3c0d64ea241bf9f6afbeed3 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 27 Mar 2017 18:14:49 +0200 Subject: Don't suspend hel when on power supply --- hel.nix | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hel.nix b/hel.nix index f0c95ebf..829f3cc7 100644 --- a/hel.nix +++ b/hel.nix @@ -474,5 +474,28 @@ systemd.user.services."pulseaudio".enable = lib.mkForce false; systemd.user.services."ssh-agent".enable = lib.mkForce false; systemd.user.sockets."pulseaudio".enable = lib.mkForce false; + + systemd.services."prevent-suspend" = { + description = "Inhibit handling of lid-switch and sleep"; + + path = with pkgs; + [ systemd coreutils ]; + + script = '' + #!{pkgs.stdenv.shell} + + exec systemd-inhibit --what=handle-lid-switch:sleep --why="prevent-suspend.service" --mode=block sleep infinity + ''; + + serviceConfig = { + Type = "simple"; + }; + }; + + services.udev.path = with pkgs; [ systemd ]; + services.udev.extraRules = '' + SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="systemctl --no-block start prevent-suspend.service" + SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="systemctl --no-block stop prevent-suspend.service" + ''; } -- cgit v1.2.3