From c9438566c8b67b353623942ae01219b1b94a1e04 Mon Sep 17 00:00:00 2001 From: Kate Temkin Date: Thu, 12 Jun 2025 02:15:11 +0200 Subject: [PATCH] trailblazer: update command script to send status, too --- nixos/hosts/trailblazer/default.nix | 49 ++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/nixos/hosts/trailblazer/default.nix b/nixos/hosts/trailblazer/default.nix index 8e9386c..7c2639a 100644 --- a/nixos/hosts/trailblazer/default.nix +++ b/nixos/hosts/trailblazer/default.nix @@ -65,7 +65,36 @@ let print("[I] Everything should be... well, not-shiny, captain!") - if verb == "lights/ledsoff": + elif verb == "monitors/off": + print("[I] Got a 'monitors off' request. Adding DPMS nulls.") + + # Turn off monitors for any X11 anything. + for auth in g`/tmp/xauth_*`: + print(f"[I] Turning off monitors on X instance with auth file {auth}.") + !(env DISPLAY=:0 XAUTHORITY=@(auth) xset dpms force off) + + # Turn off monitors on each niri session, + sockets = g`/var/run/user/1000/niri*.sock` + for socket in sockets: + print(f"[I] Turning off monitors on niri instance {socket}.") + !(env NIRI_SOCKET=@(socket) niri msg action power-off-monitors) + + + elif verb == "monitors/on": + print("[I] Got a 'monitors on' request. Removing DPMS nulls.") + + # Turn off monitors for any X11 anything. + for auth in g`/tmp/xauth_*`: + print(f"[I] Turning on monitors on X instance with auth file {auth}.") + !(env DISPLAY=:0 XAUTHORITY=@(auth) xset dpms force on) + + # Turn off monitors on each niri session, + sockets = g`/var/run/user/1000/niri*.sock` + for socket in sockets: + print(f"[I] Turning on monitors on niri instance {socket}.") + !(env NIRI_SOCKET=@(socket) niri msg action power-on-monitors) + + elif verb == "lights/ledsoff": print("[I] Turning off RGB leds.") !(${ledOffScript}/bin/ledsoff) @@ -102,6 +131,14 @@ let print("----------------------------") ''; + statusScript = pkgs.writeScriptBin "trailblazer-status-daemon" '' + #!${pkgs.xonsh}/bin/xonsh + + print("[I] Trailblazer status service started. Updating every 10s.") + while True: + sleep 10 + mosquitto_pub -h mitsuru -t trailblazer/monitors/status -m $(cat /sys/class/drm/card1-HDMI-A-1/dpms) + ''; in { system.stateVersion = "23.11"; @@ -221,6 +258,16 @@ in script = "${commandScript}/bin/trailblazer-command-daemon"; }; + systemd.services.trailblazer-status = { + description = "trailblazer status service"; + + # Start once we're online. + wantedBy = [ "default.target" ]; + wants = [ "network-online.target" ]; + after = [ "network-online.target" ]; + + script = "${statusScript}/bin/trailblazer-status-daemon"; + }; # # Let trailblazer share its GPS with the house devices.