Files
lhns--steam-frame-nix/modules/steamvr-debugger.nix
T
Pierre Kisters b7b32d0aa9 steamvr-debugger: set DebuggerEnabled only while SteamVR runs
The key used to be merged into steamvr.vrsettings for good (reset at the
next start after disabling, via a marker). Now it is on only while SteamVR
runs and nothing depends on Nix to undo it:

- before each SteamVR start, the oneshot runs `install.sh
  steamvr-debugger-arm`: the key's value goes to
  ~/.local/state/steam-frame-nix/steamvr-debugger.armed ("absent", "false",
  "nofile"), the key is set (jq --indent 3, mode kept), and a runtime
  drop-in $XDG_RUNTIME_DIR/systemd/user/steamvr.service.d/
  50-steam-frame-nix-debugger.conf runs a /usr/bin-only restore script from
  $XDG_RUNTIME_DIR/steam-frame-nix on ExecStopPost= (daemon-reload only when
  newly written: once per boot). A key that is already true without .armed
  is the user's own and never touched. The old marker migrates to .armed
  ("absent").
- when SteamVR stops, the key goes back to its previous value (removed if
  it was absent, the file too if it only existed for the key) and .armed
  is removed. .armed is the only trace a power loss can leave; the next
  start or steam-frame-nix-cleanup resolves it.
- disabled: no unit and no drop-in at all; the orphan cleanup restores the
  key once SteamVR is stopped (or leaves it to the runtime drop-in while it
  runs).

A daemon-reload from a oneshot pulled in by a pending start job was tried
on dummy user units: the job survives and the new ExecStopPost= applies,
also on restart (stop, then the oneshot, then start).
checks.cleanup covers arming, re-arming, restoring and the user's own key.
2026-09-29 00:02:57 +02:00

84 lines
3.5 KiB
Nix

# SteamVR web helper debugger: DevTools of the dashboard (vrwebhelper) on
# 127.0.0.1:8087, for dashboard patches. On automatically (mkDefault) when a
# patch targets port 8087.
#
# The port opens only with VRWebHelper/DebuggerEnabled in
# ~/.config/openvr/config/steamvr.vrsettings, which SteamVR rewrites from
# memory, so it can't be a store link or be edited while SteamVR runs. The key
# is set only while SteamVR runs:
# - before each start, the steamvr-webhelper-debugger oneshot (drop-in
# Wants/After on steamvr.service; ExecStartPre= would be too late, vrserver
# starts in the unit's own chain) runs `install.sh steamvr-debugger-arm`:
# it keeps the key's value in $XDG_STATE_HOME/steam-frame-nix/
# steamvr-debugger.armed (a key already true is the user's own and left
# alone), sets the key, and writes a runtime drop-in
# ($XDG_RUNTIME_DIR/systemd/user/steamvr.service.d) with a /usr/bin-only
# restore script (daemon-reload only when it is new, i.e. once per boot);
# - when SteamVR stops, that ExecStopPost= puts the value back and removes
# .armed. The runtime pieces don't depend on Nix, so this also works after
# a rollback or uninstall; they are gone at reboot, and .armed (the only
# trace after a power loss) is resolved by the next start or
# steam-frame-nix-cleanup.
# Off: no unit and no drop-in; cleanup restores the key once SteamVR is
# stopped. Developer Mode forwards the port to 0.0.0.0:8088 (README,
# "DevTools on the LAN"); our patches use 127.0.0.1 only.
{ config, lib, pkgs, ... }:
let
cfg = config.steamFrame.steamvrDebugger;
usesDebugger = p: builtins.match "[a-z]+://[^/]*:8087(/.*)?" p.endpoint != null;
arm = pkgs.callPackage ./cleanup/package.nix {
name = "steamvr-webhelper-debugger";
command = "steamvr-debugger-arm";
};
in {
imports = [ ./cleanup.nix ./steam-ui-patches.nix ];
options.steamFrame.steamvrDebugger.enable = lib.mkOption {
type = lib.types.bool;
default = false;
defaultText = lib.literalMD ''
on automatically when a SteamVR dashboard patch (a
`steamFrame.uiPatches.patches` entry on port 8087) is enabled
'';
description = ''
SteamVR's web helper debugger (dashboard DevTools on 127.0.0.1:8087,
VRWebHelper/DebuggerEnabled in steamvr.vrsettings), needed by SteamVR
dashboard patches, which turn it on automatically. Set only while
SteamVR runs (from its next start; the first time needs one SteamVR
restart) and put back to its previous value when SteamVR stops.
Developer Mode also forwards the port to the LAN (0.0.0.0:8088).
'';
};
config = lib.mkMerge [
{
steamFrame.steamvrDebugger.enable =
lib.mkDefault (lib.any usesDebugger config.steamFrame.uiPatches.patches);
}
(lib.mkIf cfg.enable {
steamFrame.cleanup.keep = [ "debugger" ];
systemd.user.services.steamvr-webhelper-debugger = {
Unit = {
Description = "Set SteamVR VRWebHelper/DebuggerEnabled until SteamVR stops (steam-frame-nix)";
Before = [ "steamvr.service" ];
};
Service = {
Type = "oneshot";
Environment = [ "STEAM_FRAME_NIX_RUNTIME_DIR=%t" ];
ExecStart = lib.getExe arm;
};
};
# Wants=, not Requires=: SteamVR still starts if this fails.
xdg.configFile."systemd/user/steamvr.service.d/webhelper-debugger.conf".text = ''
[Unit]
Wants=steamvr-webhelper-debugger.service
After=steamvr-webhelper-debugger.service
'';
})
];
}