Sunshine: Difference between revisions

Cdro (talk | contribs)
Correct information about GameStream protocol (Moonlight is an open-source implementation)
m Install: Since the pr got merged into unstable, the snippet applies for <26.05
Tags: Mobile edit Mobile web edit Visual edit
 
(12 intermediate revisions by 5 users not shown)
Line 2: Line 2:


== Install ==
== Install ==
To install Sunshine, you will need to open up firewall ports, install udev rules and provide a setuid wrapper,
so that sunshine can capture the display:


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
 
{ pkgs, ... }: {
To install Sunshine and enable it you can use the following snippet:
  environment.systemPackages = [
 
    pkgs.sunshine
{{file|3=<nowiki>
    pkgs.moonlight-qt #for testing purposes.
   services.sunshine = {
  ];
   services.udev.packages = [ pkgs.sunshine ]; # allow access to create virtual input interfaces.
  networking.firewall = {
     enable = true;
     enable = true;
     allowedTCPPorts = [ 47984 47989 47990 48010 ];
     autoStart = true;
     allowedUDPPortRanges = [
     capSysAdmin = true; # only needed for Wayland -- omit this when using with Xorg
      { from = 47998; to = 48000; }
    openFirewall = true;
      { from = 8000; to = 8010; }
    ];
   };
   };
  # Prevents this error:
</nowiki>|name=/etc/nixos/configuration.nix|lang=nix}}
  # Fatal: You must run [sudo setcap cap_sys_admin+p $(readlink -f sunshine)] for KMS display capture to work!
 
  security.wrappers.sunshine = {
==== Uinput setup ====
    owner = "root";
To permit sunshine to emulate input devices, for example to create a virtual mouse and keyboard, add yourself to the <code>uinput</code> group<ref>https://github.com/NixOS/nixpkgs/pull/493109</ref><ref>https://github.com/NixOS/nixpkgs/issues/455737#issuecomment-3451112321</ref>{{File|3=users.users.myuser = {
    group = "root";
  extraGroups = [ "uinput" ];
    capabilities = "cap_sys_admin+p";
};|name=/etc/nixos/configuration.nix|lang=nix}}
    source = "${pkgs.sunshine}/bin/sunshine";
 
  };
For <26.05 stable branch system versions, you need to also enable and create the <code>uinput</code> kernel module and user group.
  # Needed for network discovery
{{File|3=hardware.uinput.enable = true;|name=/etc/nixos/configuration.nix|lang=nix}}
  services.avahi.enable = true;
  services.avahi.publish.enable = true;
  services.avahi.publish.userServices = true;
}
</nowiki>}}


== Connecting to the host ==
== Connecting to the host ==


Sunshine needs to be started with the <pre>sunshine</pre> command.
When installed via the NixOS module, Sunshine is configured as a Systemd user unit, and will start automatically on login to a graphical session. Note that a logout/login or restart may be required for Sunshine to start after initially adding it to your configuration due to limitations of NixOS' handling of user units with <code>nixos-rebuild</code>. 
 
If <code>services.sunshine.autoStart</code> is set to <code>false</code>, Sunshine needs to be started with the <code>sunshine</code> command.


You may have to manually add the host running Sunshine to your Moonlight client. This, thankfully, is not hard to do.
You may have to manually add the host running Sunshine to your Moonlight client. This, thankfully, is not hard to do.
Line 47: Line 37:
If this doesn’t work you should double check the port in the Sunshine’s WebGUI. You can access this from the Host PC in a web browser <code>https://localhost:47990</code>
If this doesn’t work you should double check the port in the Sunshine’s WebGUI. You can access this from the Host PC in a web browser <code>https://localhost:47990</code>


== Attribution ==
== Limitations ==
A substantial amount of the above came from [https://www.reddit.com/r/NixOS/comments/1bq2bx4/beginners_guide_to_sunshine_gamedesktop_streaming/ this fairly wonderful guide] posted to Reddit.
At the time of writing Sunshine is unable to wake sleeping display<ref>https://github.com/orgs/LizardByte/discussions/439</ref> (e.g. when screen is locked), which makes impossible to connect to the main session of your host PC. Can be somehow avoided by creating a virtual display and running Sunshine through it.
 
== Troubleshooting ==
 
=== Running Steam Big Picture on Wayland ===
While using Wayland on non-wlroots compositors, [https://docs.lizardbyte.dev/projects/sunshine/latest/md_docs_2getting__started.html you need to have] <code>capSysAdmin = true;</code> in Sunshine config for KMS to capture screen properly. But this parameter breaks any custom applications that should be started from your main user, not super-user. To avoid such issues, you need to prepend all needed commands with <code>sudo -u <username></code> <ref>https://discourse.nixos.org/t/give-user-cap-sys-admin-p-capabillity/62611/3?u=dmchmk</ref>:


Before: <syntaxhighlight lang="json">
    {
      "name": "Steam Big Picture",
      "detached": [
        "setsid steam steam://open/bigpicture"
      ],
      "prep-cmd": [
        {
          "do": "",
          "undo": "setsid steam steam://close/bigpicture"
        }
      ],
      "image-path": "steam.png"
    }
</syntaxhighlight>After: <syntaxhighlight lang="json">
    {
      "name": "Steam Big Picture",
      "detached": [
        "sudo -u venya setsid steam steam://open/bigpicture"
      ],
      "prep-cmd": [
        {
          "do": "",
          "undo": "sudo -u venya setsid steam steam://close/bigpicture"
        }
      ],
      "image-path": "steam.png"
    }


</syntaxhighlight>
[[Category:Applications]]
[[Category:Applications]]
[[Category:Gaming]]
[[Category:Gaming]]