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.
This commit is contained in:
Pierre Kisters committed 2026-09-29 00:02:57 +02:00
1 parent 1ad0dd751e
commit b7b32d0aa9
4 files changed
+140 -68

No files matched your search

+52
View File
@@ -86,6 +86,10 @@ Commands:
Show Nix, Home Manager and user service state, and what
'cleanup --all' would remove.
steamvr-debugger-arm
Internal (run before each SteamVR start by steamFrame.steamvrDebugger):
set VRWebHelper.DebuggerEnabled until SteamVR stops.
Options:
--yes, -y Don't ask; answer yes to every question.
--help, -h Show this help.
@@ -577,6 +581,53 @@ debugger_remove_hook() {
return 0
}
# Before each SteamVR start (the steamvr-webhelper-debugger oneshot of
# steamFrame.steamvrDebugger): remember the key's value in
# steamvr-debugger.armed, set it to true and make sure the runtime drop-in
# puts it back when SteamVR stops. A key that is already true (without
# .armed) is the user's own and never touched.
cmd_debugger_arm() {
local cur tmp
need_not_root
command -v jq >/dev/null 2>&1 || die "jq not found"
if [[ -f $DEBUGGER_MARKER_V1 ]]; then # marker of older versions: key was absent
mkdir -p "$SFN_STATE"
[[ -f $DEBUGGER_ARMED ]] || printf 'absent\n' >"$DEBUGGER_ARMED"
rm -f -- "$DEBUGGER_MARKER_V1"
info "migrated $DEBUGGER_MARKER_V1 to $DEBUGGER_ARMED"
fi
if [[ ! -f $DEBUGGER_ARMED ]]; then
if [[ -f $VRSETTINGS ]]; then
cur="$(jq -r 'if (.VRWebHelper | type) == "object" and (.VRWebHelper | has("DebuggerEnabled"))
then .VRWebHelper.DebuggerEnabled | tostring else "absent" end' "$VRSETTINGS")" \
|| die "can't read $VRSETTINGS"
else
cur=nofile
fi
case $cur in
true) info "VRWebHelper.DebuggerEnabled is already true (not set by steam-frame-nix): left as is"; return 0 ;;
false|absent|nofile) ;;
*) warn "VRWebHelper.DebuggerEnabled is $cur; left as is"; return 0 ;;
esac
mkdir -p "$SFN_STATE"
printf '%s\n' "$cur" >"$DEBUGGER_ARMED"
fi
if [[ ! -f $VRSETTINGS ]]; then
mkdir -p "${VRSETTINGS%/*}"
printf '{}\n' >"$VRSETTINGS"
fi
if [[ $(jq '.VRWebHelper.DebuggerEnabled' "$VRSETTINGS") != true ]]; then
tmp="$(mktemp "$VRSETTINGS.XXXXXX")"
jq --indent 3 '.VRWebHelper.DebuggerEnabled = true' "$VRSETTINGS" >"$tmp" || { rm -f "$tmp"; die "can't write $VRSETTINGS"; }
chmod --reference="$VRSETTINGS" "$tmp"
mv -f "$tmp" "$VRSETTINGS"
info "VRWebHelper.DebuggerEnabled set to true until SteamVR stops (before: $(<"$DEBUGGER_ARMED"))"
else
info "VRWebHelper.DebuggerEnabled already true (set by steam-frame-nix)"
fi
debugger_ensure_hook || true
}
clean_debugger() { # keep
local keep=$1 prior='' state cur out
if [[ -f $DEBUGGER_ARMED ]]; then
@@ -1085,6 +1136,7 @@ main() {
uninstall) cmd_uninstall "$@" ;;
status) cmd_status "$@" ;;
cleanup) cmd_cleanup "$@" ;;
steamvr-debugger-arm) cmd_debugger_arm "$@" ;;
-h|--help|help) usage ;;
'') usage >&2; exit 2 ;;
*) printf 'unknown command: %s\n\n' "$cmd" >&2; usage >&2; exit 2 ;;