Two streams of fixes shipped together. Headless persistence (root cause of "Fatal: Unable to find display or encoder during startup") - bin/sunshine-stream-undo.sh: stop removing HEADLESS-1 on disconnect. Create-on-connect / destroy-on-disconnect raced with Sunshine's startup encoder probe and made every restart fail with a fatal-but-misleading warning. The output now lives across stream sessions; sunshine-stream- do.sh just resizes it per client. - files/headless-prestart.conf: systemd-user drop-in that runs 'hyprctl output create headless' (non-fatal) before Sunshine starts, so HEADLESS-1 exists before the encoder probe. - lib/headless.sh: install_headless_prestart_dropin resolves the actual unit name (sunshine.service or app-dev.lizardbyte.app.Sunshine.service) and lands the drop-in under ~/.config/systemd/user/<unit>.d/. - lib/service.sh: enable_sunshine_service calls install_headless_prestart_ dropin when STREAM_MODE=headless. Placed after ensure_sunshine_unit_ present so the unit name is settled when the drop-in is written. - install.sh: comment noting the drop-in install is deferred to the service-enable step. Web UI lockdown + tunnel-friendly certs - lib/config.sh: emits origin_web_ui_allowed = pc. Sunshine rejects web UI requests from anywhere other than localhost regardless of bind address. Streaming/pairing (47989) stays LAN-accessible. Inline comment documents the SSH tunnel recipe. - lib/certs.sh: add DNS:localhost and IP:127.0.0.1 to host cert SANs so the tunneled https://localhost:47990 URL doesn't trigger a hostname mismatch. Idempotency check now requires those SANs too. Misc. - files/sunshine.service: fallback unit also gains the prestart ExecStartPre. - lib/service.sh: ensure_sunshine_unit_present aliases the reverse-DNS Sunshine unit as sunshine.service when sunshine-bin's short-name unit isn't installed.
87 lines
2.9 KiB
Bash
87 lines
2.9 KiB
Bash
#!/usr/bin/env bash
|
|
# Write a tuned ~/.config/sunshine/sunshine.conf for low-latency LAN streaming.
|
|
# Only overwrites if (a) no config exists, or (b) our managed marker is present.
|
|
|
|
SUNSHINE_CONF_DIR="$HOME/.config/sunshine"
|
|
SUNSHINE_CONF="$SUNSHINE_CONF_DIR/sunshine.conf"
|
|
MANAGED_MARKER="# managed-by: omarchy-moonlight"
|
|
|
|
write_sunshine_config() {
|
|
local mode="${1:-mirror}"
|
|
mkdir -p "$SUNSHINE_CONF_DIR"
|
|
|
|
if [[ -f "$SUNSHINE_CONF" ]] && ! grep -qF "$MANAGED_MARKER" "$SUNSHINE_CONF"; then
|
|
ok "Existing sunshine.conf is user-managed — leaving it alone"
|
|
info " To re-apply tuned defaults, delete $SUNSHINE_CONF and re-run install.sh"
|
|
return 0
|
|
fi
|
|
|
|
local encoder_block
|
|
case "$GPU_VENDOR" in
|
|
nvidia)
|
|
encoder_block=$'encoder = nvenc\nnvenc_preset = p1\nnvenc_tune = ll\nnvenc_rc = cbr\nnvenc_coder = auto'
|
|
;;
|
|
amd)
|
|
encoder_block=$'encoder = vaapi\namd_quality = speed\namd_rc = cbr\namd_usage = ultralowlatency'
|
|
;;
|
|
intel)
|
|
encoder_block=$'encoder = quicksync\nqsv_preset = veryfast\nqsv_coder = auto'
|
|
;;
|
|
*)
|
|
encoder_block=$'# encoder auto-detected by Sunshine'
|
|
;;
|
|
esac
|
|
|
|
local capture_block
|
|
case "$mode" in
|
|
headless)
|
|
# wlr capture of the Hyprland headless output that prep-cmd hooks create.
|
|
# global_prep_cmd is parsed as a JSON array by Sunshine, so keep it on one line.
|
|
capture_block="# Capture: wlr — captures a Hyprland headless output created on stream start.
|
|
capture = wlr
|
|
output_name = HEADLESS-1
|
|
|
|
# Hooks that create/resize HEADLESS-1 on stream start and remove it on stop.
|
|
global_prep_cmd = [{\"do\":\"${DO_SCRIPT}\",\"undo\":\"${UNDO_SCRIPT}\"}]"
|
|
;;
|
|
mirror|*)
|
|
capture_block="# Capture: KMS (DRM) — the right choice on Wayland.
|
|
capture = kms"
|
|
;;
|
|
esac
|
|
|
|
info "Writing tuned $SUNSHINE_CONF (GPU: $GPU_VENDOR, mode: $mode)"
|
|
cat >"$SUNSHINE_CONF" <<EOF
|
|
$MANAGED_MARKER
|
|
# Generated by omarchy-moonlight install.sh on $(date -Iseconds)
|
|
# Delete this marker line to take ownership; the installer will then leave the file alone.
|
|
#
|
|
# Tuned for low-latency LAN streaming on Hyprland/Wayland.
|
|
# Tune further via the web UI at https://localhost:47990
|
|
|
|
sunshine_name = ${HOSTNAME_SHORT}
|
|
|
|
$capture_block
|
|
|
|
# Encoder tuned for $GPU_VENDOR
|
|
$encoder_block
|
|
|
|
# Threading — more threads helps high-bitrate H.265/AV1.
|
|
min_threads = 4
|
|
|
|
# Use the PipeWire pulse compatibility layer for audio.
|
|
audio_sink = pulse
|
|
|
|
# Keyboard / mouse / gamepad pass-through via /dev/uinput.
|
|
# (Requires user to be in the 'input' group; install.sh handles this.)
|
|
|
|
# Lock the web UI to localhost-only regardless of what the socket binds to.
|
|
# Reach the admin panel from another machine via an SSH tunnel:
|
|
# ssh -L 47990:127.0.0.1:47990 <user>@<host>
|
|
# then open https://localhost:47990 in a browser. The streaming/pairing port
|
|
# (47989) stays LAN-accessible — only the admin UI is locked down.
|
|
origin_web_ui_allowed = pc
|
|
EOF
|
|
ok "Wrote sunshine.conf"
|
|
}
|