From 662cf77b2194e9c2afbd0d978b770394f257a0b4 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Tue, 6 Feb 2024 17:07:41 +0100 Subject: [PATCH] hephaestus: add lid-listener service for autorandr --- hosts/hephaestus/default.nix | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hosts/hephaestus/default.nix b/hosts/hephaestus/default.nix index 0a0f3bc..deb7cde 100644 --- a/hosts/hephaestus/default.nix +++ b/hosts/hephaestus/default.nix @@ -213,6 +213,29 @@ }; }; + systemd.services.autorandr-lid-listener = { + wantedBy = ["multi-user.target"]; + description = "Listening for lid events to invoke autorandr"; + + serviceConfig = { + Type = "simple"; + ExecStart = let + stdbufExe = lib.getExe' pkgs.coreutils "stdbuf"; + libinputExe = lib.getExe' pkgs.libinput "libinput"; + grepExe = lib.getExe pkgs.gnugrep; + autorandrExe = lib.getExe pkgs.autorandr; + in pkgs.writeShellScript "lid-listener.sh" '' + ${stdbufExe} -oL ${libinputExe} debug-events | + ${grepExe} -E --line-buffered '^[[:space:]-]+event[0-9]+[[:space:]]+SWITCH_TOGGLE[[:space:]]' | + while read line; do + ${pkgs.systemd}/bin/systemctl start --no-block autorandr.service + done + ''; + Restart = "always"; + RestartSec = "30"; + }; + }; + # Configure console keymap console.keyMap = "us";