From f76594dba28559e7e0151a5a68a7425219cec50c Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Wed, 8 Jan 2025 18:10:54 -0500 Subject: [PATCH] sunshine: hack steam big picture mode --- nixosModules/services/sunshine.nix | 67 +++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/nixosModules/services/sunshine.nix b/nixosModules/services/sunshine.nix index 53406580..65d13728 100644 --- a/nixosModules/services/sunshine.nix +++ b/nixosModules/services/sunshine.nix @@ -1,18 +1,81 @@ -{pkgs, ...}: { +{pkgs, ...}: let + steam-run-url = pkgs.writeShellApplication { + name = "steam-run-url"; + + runtimeInputs = [ + pkgs.coreutils # For `id` commands + ]; + + text = '' + echo "$1" > "/run/user/$(id --user)/steam-run-url.fifo" + ''; + }; +in { environment.systemPackages = with pkgs; [ moonlight-qt + steam-run-url ]; services = { sunshine = { enable = true; + + applications = { + apps = [ + { + auto-detach = "true"; + + detached = [ + "${steam-run-url}/bin/steam-run-url steam://open/bigpicture" + ]; + + image-path = "steam.png"; + name = "Steam - Big Picture Mode"; + output = "steam.txt"; + } + ]; + }; + + autoStart = true; capSysAdmin = true; openFirewall = true; - autoStart = true; }; udev.extraRules = '' KERNEL=="uinput", GROUP="input", MODE="0660" OPTIONS+="static_node=uinput" ''; }; + + systemd.user.services = { + steam-run-url-service = { + enable = true; + after = ["graphical-session.target"]; + description = "Listen and starts steam games by id."; + partOf = ["graphical-session.target"]; + path = [pkgs.steam]; + + script = toString (pkgs.writers.writePython3 "steam-run-url-service" {} '' + import os + from pathlib import Path + import subprocess + + pipe_path = Path(f'/run/user/{os.getuid()}/steam-run-url.fifo') + try: + pipe_path.parent.mkdir(parents=True, exist_ok=True) + pipe_path.unlink(missing_ok=True) + os.mkfifo(pipe_path, 0o600) + while True: + with pipe_path.open(encoding='utf-8') as pipe: + subprocess.Popen(['steam', pipe.read().strip()]) + finally: + pipe_path.unlink(missing_ok=True) + ''); + + serviceConfig.Restart = "on-failure"; + wantedBy = ["graphical-session.target"]; + wants = ["graphical-session.target"]; + }; + + sunshine.path = [steam-run-url]; + }; }