From 39f44daabe1e2fc2f6ac7590023c0d08f5e46983 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 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/hosts/hephaestus/default.nix b/hosts/hephaestus/default.nix index 0a0f3bc..6c03c62 100644 --- a/hosts/hephaestus/default.nix +++ b/hosts/hephaestus/default.nix @@ -213,6 +213,30 @@ }; }; + 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";