diff options
author | tv <tv@krebsco.de> | 2023-01-11 19:35:55 +0100 |
---|---|---|
committer | tv <tv@krebsco.de> | 2023-01-11 19:36:03 +0100 |
commit | 6f6cf85808a8fbc6fd0b8c51114224a17e9000d1 (patch) | |
tree | 9c008e84a2f8f1cf5f840eba2b6cb732f129f5a4 /tv | |
parent | df5d418dc7f6ff160cc4e05a73ca33631394d3be (diff) |
tv lidControl: init
Diffstat (limited to 'tv')
-rw-r--r-- | tv/3modules/default.nix | 1 | ||||
-rw-r--r-- | tv/3modules/lidControl.nix | 45 |
2 files changed, 46 insertions, 0 deletions
diff --git a/tv/3modules/default.nix b/tv/3modules/default.nix index b6b4faa..ea3efbc 100644 --- a/tv/3modules/default.nix +++ b/tv/3modules/default.nix @@ -8,6 +8,7 @@ ./hw.nix ./im.nix ./iptables.nix + ./lidControl.nix ./org.freedesktop.machine1.host-shell.nix ./slock.nix ./x0vncserver.nix diff --git a/tv/3modules/lidControl.nix b/tv/3modules/lidControl.nix new file mode 100644 index 0000000..6a48da1 --- /dev/null +++ b/tv/3modules/lidControl.nix @@ -0,0 +1,45 @@ +with import ./lib; +{ config, pkgs, ... }: { + options = { + tv.lidControl.enable = mkEnableOption "tv.lidControl"; + }; + config = let + cfg = config.tv.lidControl; + in mkIf cfg.enable { + services.acpid.enable = true; + services.acpid.lidEventCommands = /* sh */ '' + set -- $1 + + # usage: vt_is_xserver NUMBER + vt_is_xserver() { + ${pkgs.iproute}/bin/ss -lp src unix:/tmp/.X11-unix/X* | + ${pkgs.gnused}/bin/sed -n 's|.*/tmp/.X11-unix/X\([0-9]\+\)\>.*|\1|p' | + ${pkgs.gnugrep}/bin/grep -Fqx "$1" + } + + console=$(${pkgs.kbd}/bin/fgconsole) + + if vt_is_xserver "$console"; then + # usage: run_on_display COMMAND [ARG...] + run_on_display() { + owner=$(${pkgs.coreutils}/bin/stat -c %u /tmp/.X11-unix/X$console) + ${pkgs.systemd}/bin/systemd-run -GPq \ + -E DISPLAY=:$console \ + --uid=$owner \ + "$@" + } + case $3 in + open) + run_on_display ${pkgs.xorg.xset}/bin/xset dpms force on + ;; + close) + run_on_display ${pkgs.xorg.xset}/bin/xset dpms force off + ;; + esac + fi + ''; + services.logind.lidSwitch = "ignore"; + services.logind.lidSwitchDocked = "ignore"; + services.logind.lidSwitchExternalPower = "ignore"; + }; +} |