|
| 1 | +{ |
| 2 | + flake-inputs, |
| 3 | + config, |
| 4 | + pkgs, |
| 5 | + ... |
| 6 | +}: |
| 7 | +let |
| 8 | + inherit (flake-inputs.self.pkgs-lib.${pkgs.stdenv.hostPlatform.system}) writeNuWith; |
| 9 | + inherit (flake-inputs.self.packages.${pkgs.stdenv.hostPlatform.system}) edid-generator; |
| 10 | +in |
| 11 | +{ |
| 12 | + nix.settings = { |
| 13 | + substituters = [ "https://cache.nixos-cuda.org" ]; |
| 14 | + trusted-public-keys = [ "cache.nixos-cuda.org:74DUi4Ye579gUqzH4ziL9IyiJBlDpMRn9MBN8oNan9M=" ]; |
| 15 | + }; |
| 16 | + |
| 17 | + # Create a virtual display to render games for sunshine on |
| 18 | + hardware.display = { |
| 19 | + edid.packages = [ |
| 20 | + (pkgs.runCommand "VTCL65C825.bin" |
| 21 | + { |
| 22 | + nativeBuildInputs = [ edid-generator ]; |
| 23 | + settings = pkgs.writers.writeJSON "edid.json" { |
| 24 | + defaultMode = { |
| 25 | + width = 1920; |
| 26 | + height = 1080; |
| 27 | + refresh = 120; |
| 28 | + }; |
| 29 | + modes = [ |
| 30 | + { |
| 31 | + width = 1920; |
| 32 | + height = 1080; |
| 33 | + refresh = 120; |
| 34 | + } |
| 35 | + { |
| 36 | + width = 1920; |
| 37 | + height = 1080; |
| 38 | + refresh = 60; |
| 39 | + } |
| 40 | + { |
| 41 | + width = 3840; |
| 42 | + height = 2160; |
| 43 | + refresh = 120; |
| 44 | + } |
| 45 | + { |
| 46 | + width = 3840; |
| 47 | + height = 2160; |
| 48 | + refresh = 60; |
| 49 | + } |
| 50 | + ]; |
| 51 | + audio = false; |
| 52 | + hdr = true; |
| 53 | + deepColor = true; |
| 54 | + dsc = false; |
| 55 | + vrr = false; |
| 56 | + listedModesOnly = false; |
| 57 | + }; |
| 58 | + } |
| 59 | + '' |
| 60 | + mkdir -p "$out/lib/firmware/edid" |
| 61 | + edid-generator $settings > "$out/lib/firmware/edid/VTCL65C825.bin" |
| 62 | + '' |
| 63 | + ) |
| 64 | + ]; |
| 65 | + |
| 66 | + # The port (DP-2) to be used must be free on the GPU, use |
| 67 | + # `ls /sys/class/drm/*/status` to find free ports. |
| 68 | + # |
| 69 | + # Using DP-2 because HDMI doesn't support 3840x2160@120. |
| 70 | + outputs."DP-2" = { |
| 71 | + edid = "VTCL65C825.bin"; |
| 72 | + mode = "e"; |
| 73 | + }; |
| 74 | + }; |
| 75 | + |
| 76 | + services.sunshine = { |
| 77 | + enable = true; |
| 78 | + package = pkgs.sunshine.override { cudaSupport = true; }; |
| 79 | + |
| 80 | + openFirewall = true; |
| 81 | + settings = { |
| 82 | + sunshine_name = config.networking.hostName; |
| 83 | + system_tray = false; |
| 84 | + encoder = "nvenc"; |
| 85 | + |
| 86 | + # TODO(tlater): Switch to portalgrab once released: |
| 87 | + # https://github.com/LizardByte/Sunshine/pull/4417 |
| 88 | + capture = "wlr"; |
| 89 | + output_name = 1; |
| 90 | + }; |
| 91 | + |
| 92 | + applications.apps = [ |
| 93 | + ( |
| 94 | + let |
| 95 | + runScript = writeNuWith { |
| 96 | + packages = [ |
| 97 | + pkgs.util-linux |
| 98 | + config.programs.sway.package |
| 99 | + config.programs.steam.package |
| 100 | + ]; |
| 101 | + }; |
| 102 | + in |
| 103 | + { |
| 104 | + name = "Steam Big Picture"; |
| 105 | + cmd = |
| 106 | + (runScript "run-steam" /* nu */ '' |
| 107 | + swaymsg output DP-2 enable |
| 108 | + swaymsg workspace sunshine gaps outer 0 |
| 109 | + swaymsg workspace sunshine gaps inner 0 |
| 110 | + swaymsg workspace sunshine output DP-2 |
| 111 | + swaymsg focus output DP-2 |
| 112 | + swaymsg assign '[title="Steam Big Picture Mode"]' → workspace steam |
| 113 | +
|
| 114 | + try { |
| 115 | + setsid steam steam://open/bigpicture |
| 116 | + } |
| 117 | + '').outPath; |
| 118 | + |
| 119 | + auto-detach = false; |
| 120 | + prep-cmd = [ |
| 121 | + { |
| 122 | + undo = |
| 123 | + (runScript "close-steam" /* nu */ '' |
| 124 | + swaymsg output DP-2 disable |
| 125 | +
|
| 126 | + sleep 5sec |
| 127 | + if (ps | where pid == (cat ~/.steampid)) != [ ] { |
| 128 | + try { |
| 129 | + steam -shutdown |
| 130 | + } |
| 131 | + } |
| 132 | + '').outPath; |
| 133 | + } |
| 134 | + ]; |
| 135 | + } |
| 136 | + ) |
| 137 | + ]; |
| 138 | + }; |
| 139 | + |
| 140 | +} |
0 commit comments