Skip to content

Commit

Permalink
sunshine: hack steam big picture mode
Browse files Browse the repository at this point in the history
  • Loading branch information
alyraffauf committed Jan 8, 2025
1 parent 79843c8 commit f76594d
Showing 1 changed file with 65 additions and 2 deletions.
67 changes: 65 additions & 2 deletions nixosModules/services/sunshine.nix
Original file line number Diff line number Diff line change
@@ -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];
};
}

0 comments on commit f76594d

Please sign in to comment.