refactor: use sunshine service

This commit is contained in:
Giulio De Pasquale 2024-10-31 08:33:56 +00:00
parent 2487717aaf
commit f7f1da25ed

View File

@ -30,41 +30,12 @@ let
executable = true; executable = true;
destination = "/bin/resolution.sh"; destination = "/bin/resolution.sh";
}; };
configFile = pkgs.writeText "sunshine.conf" sunshinePkg = (pkgs.localPkgs.sunshine.override { cudaSupport = true; cudaPackages = pkgs.cudaPackages; boost = pkgs.unstablePkgs.boost186; });
''
capture=nvfbc
encoder=nvenc
wan_encryption_mode = 0
lan_encryption_mode = 0
origin_web_ui_allowed=lan
channels=2
min_threads=12
global_prep_cmd=[{"do":"${pkgs.bash}/bin/bash -c \"${resolutionScript}/bin/resolution.sh ''${SUNSHINE_CLIENT_WIDTH} ''${SUNSHINE_CLIENT_HEIGHT} ''${SUNSHINE_CLIENT_FPS}\""}]
'';
sunshinePkg = (pkgs.unstablePkgs.sunshine.override { cudaSupport = true; });
in in
{ {
boot.kernelModules = [ "uinput" ]; boot.kernelModules = [ "uinput" ];
environment = { environment.systemPackages = [ pkgs.unstablePkgs.gamemode ];
systemPackages = with pkgs; [
sunshinePkg
xorg.xrandr
xorg.xorgserver
xorg.libxcvt
gamemode
];
variables = {
VDPAU_DRIVER = "nvidia";
LIBVA_DRIVER_NAME = "nvidia";
NVD_BACKEND = "direct";
__GL_SYNC_TO_VBLANK = "0";
__GL_VRR_ALLOWED = "0";
DXVK_ASYNC = "1";
};
};
hardware = { hardware = {
pulseaudio.enable = true; pulseaudio.enable = true;
@ -101,15 +72,45 @@ in
}; };
services = { services = {
avahi = { sunshine = {
enable = true; enable = true;
publish.userServices = true; autoStart = true;
package = sunshinePkg;
settings = {
sunshine_name = "The Architect";
capture = "nvfbc";
encoder = "nvenc";
wan_encryption_mode = 0;
lan_encryption_mode = 0;
origin_web_ui_allowed = "lan";
min_threads = 12;
log_path = "sunshine.log";
};
applications = {
env = {
VDPAU_DRIVER = "nvidia";
LIBVA_DRIVER_NAME = "nvidia";
NVD_BACKEND = "direct";
__GL_SYNC_TO_VBLANK = "0";
__GL_VRR_ALLOWED = "0";
DXVK_ASYNC = "1";
};
apps = [
{
name = "Steam";
detached = [ "${pkgs.steam}/bin/steam" ];
prep-cmd = [
{
do = "${resolutionScript}/bin/resolution.sh $SUNSHINE_CLIENT_WIDTH $SUNSHINE_CLIENT_HEIGHT $SUNSHINE_CLIENT_FPS";
undo = "${pkgs.procps}/bin/pkill -KILL steam";
}
];
auto-detach = "true";
}
];
};
}; };
udev.extraRules = ''
KERNEL=="uinput", SUBSYSTEM=="misc", OPTIONS+="static_node=uinput", TAG+="uaccess"
'';
displayManager = { displayManager = {
sddm = { sddm = {
enable = true; enable = true;
@ -201,29 +202,11 @@ in
sound.enable = true; sound.enable = true;
systemd = { systemd.targets = {
targets = { sleep.enable = false;
sleep.enable = false; suspend.enable = false;
suspend.enable = false; hibernate.enable = false;
hibernate.enable = false; hybrid-sleep.enable = false;
hybrid-sleep.enable = false;
};
user.services.${user} = {
description = "Sunshine server";
wantedBy = [ "graphical-session.target" ];
startLimitIntervalSec = 500;
startLimitBurst = 5;
partOf = [ "graphical-session.target" ];
wants = [ "graphical-session.target" ];
after = [ "graphical-session.target" ];
path = with pkgs; [ resolutionScript gamemode ];
serviceConfig = {
ExecStart = "${sunshinePkg}/bin/sunshine ${configFile}";
Restart = "on-failure";
RestartSec = "5s";
};
};
}; };
users = { users = {