# punktfunk streaming host — systemd USER unit (`serve --gamestream` = native punktfunk/1 + the
# GameStream/Moonlight-compat planes). For a SECURE native-only host (no plain-HTTP pairing / legacy
# GCM nonce reuse — security-review #5/#9; native clients only), drop `--gamestream` from ExecStart.
#
# Install (against an already-running compositor session — the host auto-detects and follows it,
# so host.env needs no backend config):
#   mkdir -p ~/.config/systemd/user && cp scripts/punktfunk-host.service ~/.config/systemd/user/
#   cp scripts/host.env.example ~/.config/punktfunk/host.env   # defaults are right for a desktop
#   systemctl --user daemon-reload && systemctl --user enable --now punktfunk-host
#
# Self-contained boot appliance (no login, no manual steps after boot). These routes PIN the
# backend via PUNKTFUNK_COMPOSITOR — correct for a dedicated single-session box, but it turns off
# live-session auto-detection, so never do it on a desktop that switches sessions (Game Mode etc.):
#   - kwin backend (stream the Plasma desktop): also install + enable
#     punktfunk-kde-session.service (it brings up the headless KWin session this After=s), and use
#     the shipped packaging/kde/host.env (pins kwin + WAYLAND_DISPLAY=wayland-kde on purpose).
#   - gamescope backend (stream a nested app, no desktop): set PUNKTFUNK_COMPOSITOR=gamescope in
#     host.env — the host spawns gamescope per session, so no kde-session unit is needed.
#   Then `sudo loginctl enable-linger "$USER"` so user units start at boot, and reboot.
#
# The host LISTENS as soon as it starts and only touches the compositor per session (on a client
# connect), so the After= below is a soft ordering, not a hard readiness gate — the kde-session
# unit (when present) just needs to be up by the time a client streams (seconds later, user-driven).
# A missing After= unit (e.g. gamescope backend, no kde-session installed) is simply ignored.
[Unit]
Description=punktfunk GameStream + punktfunk/1 host
After=pipewire.service punktfunk-kde-session.service
# PartOf the kwin session (when present): the host's libei input uses the RemoteDesktop portal,
# whose D-Bus connection goes stale if the compositor session restarts the portal under it — the
# in-process reopen loop can't recover that, but a full restart re-establishes it. So restart the
# host whenever the kde-session restarts. Ignored when punktfunk-kde-session isn't installed
# (gamescope / other backends).
PartOf=punktfunk-kde-session.service

[Service]
EnvironmentFile=%h/.config/punktfunk/host.env
ExecStart=%h/punktfunk/target/release/punktfunk-host serve --gamestream
Restart=on-failure
RestartSec=2

[Install]
WantedBy=default.target
