Merge pull request 'sunshine: improve module' (#945) from a-kenji-imp/sunshine into main

This commit is contained in:
clan-bot
2024-03-12 19:59:09 +00:00

View File

@@ -1,4 +1,23 @@
{ pkgs, config, ... }: { pkgs, config, options, ... }:
let
cfg = options.services.sunshine;
sunshineConfiguration = pkgs.writeText "sunshine.conf" ''
address_family = both
channels = 5
pkey = /var/lib/sunshine/sunshine.key
cert = /var/lib/sunshine/sunshine.cert
file_state = /var/lib/sunshine/state.json
file_apps = /var/lib/sunshine/apps.json
credentials_file = /var/lib/sunshine/credentials.json
'';
in
{
options.services.sunshine = {
enable = pkgs.lib.mkEnableOption "Sunshine self-hosted game stream host for Moonlight";
};
config = pkgs.lib.mkMerge [
(pkgs.lib.mkIf cfg.enable
{ {
networking.firewall = { networking.firewall = {
allowedTCPPorts = [ allowedTCPPorts = [
@@ -16,7 +35,6 @@
48010 48010
]; ];
}; };
networking.firewall.allowedTCPPortRanges = [ networking.firewall.allowedTCPPortRanges = [
{ {
from = 47984; from = 47984;
@@ -32,8 +50,6 @@
environment.systemPackages = [ environment.systemPackages = [
pkgs.sunshine pkgs.sunshine
pkgs.avahi
# Convenience script, until we find a better UX
(pkgs.writers.writeDashBin "sun" '' (pkgs.writers.writeDashBin "sun" ''
${pkgs.sunshine}/bin/sunshine -1 ${ ${pkgs.sunshine}/bin/sunshine -1 ${
pkgs.writeText "sunshine.conf" '' pkgs.writeText "sunshine.conf" ''
@@ -50,35 +66,51 @@
]; ];
# Required to simulate input # Required to simulate input
hardware.uinput.enable = true;
boot.kernelModules = [ "uinput" ]; boot.kernelModules = [ "uinput" ];
security.rtkit.enable = true;
# services.udev.extraRules = '' # services.udev.extraRules = ''
# KERNEL=="uinput", SUBSYSTEM=="misc", OPTIONS+="static_node=uinput", TAG+="uaccess" # KERNEL=="uinput", SUBSYSTEM=="misc", OPTIONS+="static_node=uinput", TAG+="uaccess"
# ''; # '';
services.udev.extraRules = '' services.udev.extraRules = ''
KERNEL=="uinput", GROUP="input", MODE="0660" OPTIONS+="static_node=uinput" KERNEL=="uinput", GROUP="input", MODE="0660" OPTIONS+="static_node=uinput"
''; '';
hardware.opengl.driSupport32Bit = true;
hardware.opengl.enable = true;
security.wrappers.sunshine = { security = {
rtkit.enable = true;
wrappers.sunshine = {
owner = "root"; owner = "root";
group = "root"; group = "root";
capabilities = "cap_sys_admin+p"; capabilities = "cap_sys_admin+p";
source = "${pkgs.sunshine}/bin/sunshine"; source = "${pkgs.sunshine}/bin/sunshine";
}; };
};
systemd.tmpfiles.rules = [
"d '/var/lib/sunshine' 0770 'user' 'users' - -"
];
systemd.user.services.sunshine = { systemd.user.services.sunshine = {
description = "sunshine"; enable = true;
wantedBy = [ "graphical-session.target" ]; description = "Sunshine self-hosted game stream host for Moonlight";
environment = { startLimitBurst = 5;
DISPLAY = ":0"; startLimitIntervalSec = 500;
}; script = "/run/current-system/sw/bin/env /run/wrappers/bin/sunshine ${sunshineConfiguration}";
serviceConfig = { serviceConfig = {
ExecStart = "${config.security.wrapperDir}/sunshine"; Restart = "on-failure";
RestartSec = "5s";
ReadWritePaths = [
"/var/lib/sunshine"
];
}; };
wantedBy = [ "graphical-session.target" ];
}; };
}
)
]
# xdg.configFile."sunshine/apps.json".text = builtins.toJSON { # xdg.configFile."sunshine/apps.json".text = builtins.toJSON {
# env = "/run/current-system/sw/bin"; # env = "/run/current-system/sw/bin";
# apps = [ # apps = [
@@ -92,18 +124,4 @@
# } # }
# ]; # ];
# }; # };
# }
services = {
avahi = {
enable = true;
reflector = true;
nssmdns = true;
publish = {
enable = true;
addresses = true;
userServices = true;
workstation = true;
};
};
};
}