This is an automated archive made by the Lemmit Bot.
The original was posted on /r/nixos by /u/mrinerdy on 2024-03-28 19:09:40.
Introduction
Hey boys and girls. I’ve just started my nix journey and I’ve been enjoying the learning process. I’m still an absolute beginner (even to linux and operating systems), so do not take my post as reference material. If you are however experiencing the same issues as me, I would like to show you the nixos configuration commands that allowed me to use sunshine (the desktop/game streaming service) on nixos.
Installing Sunshine
Installing sunshine (and moonlight) on nixos is extremely simple, just add this line to the config:
environment.systemPackages = with pkgs; [
#...
pkgs.sunshine
pkgs.moonlight-qt #for testing purposes.
#...
];
After running nixos-rebuild switch
(or your preferred flavour of this command, for the flake folks) and running sunshine, you might run into the following Errors:
[2024:03:28:18:38:57]: Error: Failed to gain CAP_SYS_ADMIN
...
a ton of messages
...
[2024:03:28:18:43:01]: Fatal: Couldn't find any working encoder
[2024:03:28:18:43:01]: Error: Video failed to find working encoder
If this is the case, this is the post for you ! As with most debugging, let’s start with the first error.
CAP_SYS_ADMIN rights
For this first problem, the program is demanding to get root capabilities to function correctly (WARNING: give elevated permissions to this application at your own risk!)
This is section of the configuration file that is needed to make it stop complaining:
security.wrappers.sunshine = {
owner = "root";
group = "root";
capabilities = "cap_sys_admin+p";
source = "${pkgs.sunshine}/bin/sunshine";
};
Note: if a reader understand this better than me and knows how to restrict the rights given to this application while still allowing it to function correctly, please post a reply with some information!
Avahi
After rebuilding and running sunshine, you might run into this next problem:
[2024:03:28:18:55:06]: Error: avahi::entry_group_new() failed: Not permitted
if you have this or another problem concerning “avahi”. You might want to consider adding the following lines to your config:
services.avahi.publish.enable = true;
services.avahi.publish.userServices = true;
Ta-da ! After this, you hopefully have sunshine working! You can test by opening moonlight, and if your own hostname doesn´t show up, adding it manually by IP by typing localhost
in the top right corner.
Opening networking ports
In order for other computers to see your sunshine server, you might need to open some TCP or UDP ports. This can be easily done by adding the following to the config:
networking.firewall = {
enable = true;
allowedTCPPorts = [ 47984 47989 47990 48010 ];
allowedUDPPortRanges = [
{ from = 47998; to = 48000; }
#{ from = 8000; to = 8010; }
];
};
The ports I opened here are the ones that are listed in the sunshine web UI, some of them might not be necessary. Once again, if you are knowledgeable about this, please share your knowledge.
And that’s it ! After this I was able to connect to sunshine running on my local computer, with my tablet running moonlight while in the same network! The next step for me is figuring out how to make a vpn so that I can access my desktop computer from anywhere :)
Good luck to any beginners like me trying to figure this stuff out!