refactor(hosts): simplify streaming display configuration

Refactor the streaming display logic for the 14900k host to use the
`streamingDisplay` configuration object directly instead of separate
variables. This simplifies the monitor layout logic for both Niri and
Hyprland.

Additionally, remove the fragile `sunshineOutputIndex` option in favor
of using the stable connector name for Sunshine's `output_name`. This
prevents issues where numeric monitor indices drift after hotplugging.
The change also includes an explicit encoder list for Sunshine to avoid
probing for AV1 on hardware that does not support it.
This commit is contained in:
2026-07-18 09:35:52 -03:00
parent 6f35d60aab
commit f1bd5146a3
2 changed files with 35 additions and 77 deletions
@@ -1,14 +1,12 @@
# Headless 4K virtual output for Sunshine → Moonlight on a client TV.
#
# NVIDIA proprietary driver: both kernel params are required —
# NVIDIA: force-enable a spare DRM connector with a custom EDID via kernel params:
# video=<connector>:e force-enables the connector
# drm.edid_firmware=<connector>:… loads modes from the EDID blob
#
# Pick a connector that is disconnected on the host (check after boot):
# grep -H . /sys/class/drm/card*-*/status
#
# Reboot after changing connector or EDID. 4K@60 is realistic on RTX 2070;
# 4K@120 on a sink-less connector needs driver patches (see NVIDIA issue #1184).
# Capture is pinned to the connector by name (Sunshine `output_name`), which is
# stable across reboots/hotplug — unlike a numeric monitor index.
# Reboot after changing connector or EDID. 4K@60 is realistic on RTX 2070.
{ config, lib, pkgs, ... }:
let
cfg = config.chiasson.system.streamingDisplay;
@@ -16,14 +14,13 @@ let
edidFirmware = pkgs.runCommand "sunshine-virtual-4k-edid" {
nativeBuildInputs = [ pkgs.python3 ];
} ''
${pkgs.python3}/bin/python3 ${./generate-virtual-edid.py} $TMPDIR/${cfg.edidFileName}
mkdir -p $out/lib/firmware/edid
cp $TMPDIR/${cfg.edidFileName} $out/lib/firmware/edid/${cfg.edidFileName}
${pkgs.python3}/bin/python3 ${./generate-virtual-edid.py} $out/lib/firmware/edid/${cfg.edidFileName}
'';
# Sunshine 2025.924 wlr capture only accepts a numeric monitor index (not "DP-2").
# If the index drifts after hotplug, check:
# journalctl --user -u sunshine -b | rg 'Monitor [0-9]+ is'
# On stream start: scale + focus the virtual 4K output so streamed windows
# land there. Capture is pinned to the connector via Sunshine `output_name`,
# so no fragile numeric-index detection is needed.
streamDisplayUp = pkgs.writeShellScriptBin "stream-display-up" ''
${pkgs.niri}/bin/niri msg output ${cfg.connector} scale ${toString cfg.niriScale}
${pkgs.niri}/bin/niri msg action focus-monitor ${cfg.connector}
@@ -87,18 +84,6 @@ in
default = "DP-3";
description = "Niri monitor to refocus when a Moonlight session ends.";
};
sunshineOutputIndex = lib.mkOption {
type = lib.types.str;
default = "3";
example = "3";
description = ''
Wayland/wlr monitor index for Sunshine `output_name`. Sunshine 2025.924 ignores
connector strings like `DP-2` and falls back to monitor 0 (your primary).
Find the index with:
`journalctl --user -u sunshine -b | rg "Monitor [0-9]+ is ${cfg.connector}"`
'';
};
};
config = lib.mkIf cfg.enable (lib.mkMerge [
@@ -118,7 +103,11 @@ in
(lib.mkIf config.chiasson.system.gaming.sunshine.enable {
services.sunshine.settings = {
capture = "wlr";
output_name = cfg.sunshineOutputIndex;
# Pin capture to the virtual display by connector name (stable across
# reboots/hotplug). A numeric index drifted to the ultrawide before.
output_name = cfg.connector;
# RTX 2070 has no AV1 NVENC; avoid probing av1_nvenc.
encoder = "hevc_nvenc,h264_nvenc";
global_prep_cmd = "[{\"do\":\"${streamDisplayUp}/bin/stream-display-up\",\"undo\":\"${streamDisplayDown}/bin/stream-display-down\"}]";
};
})