nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib
2, stdenv
3, callPackage
4, fetchFromGitHub
5, fetchurl
6, fetchpatch
7, autoPatchelfHook
8, makeWrapper
9, buildNpmPackage
10, cmake
11, avahi
12, libevdev
13, libpulseaudio
14, xorg
15, libxcb
16, openssl
17, libopus
18, ffmpeg_5-full
19, boost
20, pkg-config
21, libdrm
22, wayland
23, libffi
24, libcap
25, mesa
26, curl
27, libva
28, libvdpau
29, numactl
30, amf-headers
31, svt-av1
32, vulkan-loader
33, libappindicator
34, cudaSupport ? false
35, cudaPackages ? {}
36}:
37let
38 libcbs = callPackage ./libcbs.nix { };
39 # get cmake file used to find external ffmpeg from previous sunshine version
40 findFfmpeg = fetchurl {
41 url = "https://raw.githubusercontent.com/LizardByte/Sunshine/6702802829869547708dfec98db5b8cbef39be89/cmake/FindFFMPEG.cmake";
42 sha256 = "sha256:1hl3sffv1z8ghdql5y9flk41v74asvh23y6jmaypll84f1s6k1xa";
43 };
44in
45stdenv.mkDerivation rec {
46 pname = "sunshine";
47 version = "0.19.1";
48
49 src = fetchFromGitHub {
50 owner = "LizardByte";
51 repo = "Sunshine";
52 rev = "v${version}";
53 sha256 = "sha256-fifwctVrSkAcMK8juAirIbIP64H7GKEwC+sUR/U6Q3Y=";
54 fetchSubmodules = true;
55 };
56
57 # remove pre-built ffmpeg; use ffmpeg from nixpkgs
58 patches = [
59 ./ffmpeg.diff
60 # fix for X11 not being added to libraries unless prebuilt FFmpeg is used: https://github.com/LizardByte/Sunshine/pull/1166
61 (fetchpatch {
62 url = "https://github.com/LizardByte/Sunshine/commit/a067da6cae72cf36f76acc06fcf1e814032af886.patch";
63 sha256 = "sha256-HMxM7luiFBEmFkvQtkdAMMSjAaYPEFX3LL0T/ActUhM=";
64 })
65 ];
66
67 # fetch node_modules needed for webui
68 ui = buildNpmPackage {
69 inherit src version;
70 pname = "sunshine-ui";
71 npmDepsHash = "sha256-sdwvM/Irejo8DgMHJWWCxwOykOK9foqLFFd/tuzrkxI=";
72
73 dontNpmBuild = true;
74
75 # use generated package-lock.json as upstream does not provide one
76 postPatch = ''
77 cp ${./package-lock.json} ./package-lock.json
78 '';
79
80 installPhase = ''
81 mkdir -p $out
82 cp -r node_modules $out/
83 '';
84 };
85
86 nativeBuildInputs = [
87 cmake
88 pkg-config
89 autoPatchelfHook
90 makeWrapper
91 ] ++ lib.optionals cudaSupport [
92 cudaPackages.autoAddOpenGLRunpathHook
93 ];
94
95 buildInputs = [
96 libcbs
97 avahi
98 ffmpeg_5-full
99 libevdev
100 libpulseaudio
101 xorg.libX11
102 libxcb
103 xorg.libXfixes
104 xorg.libXrandr
105 xorg.libXtst
106 xorg.libXi
107 openssl
108 libopus
109 boost
110 libdrm
111 wayland
112 libffi
113 libevdev
114 libcap
115 libdrm
116 curl
117 libva
118 libvdpau
119 numactl
120 mesa
121 amf-headers
122 svt-av1
123 libappindicator
124 ] ++ lib.optionals cudaSupport [
125 cudaPackages.cudatoolkit
126 ];
127
128 runtimeDependencies = [
129 avahi
130 mesa
131 xorg.libXrandr
132 libxcb
133 ];
134
135 cmakeFlags = [
136 "-Wno-dev"
137 ];
138
139 postPatch = ''
140 # fix hardcoded libevdev and icon path
141 substituteInPlace CMakeLists.txt \
142 --replace '/usr/include/libevdev-1.0' '${libevdev}/include/libevdev-1.0' \
143 --replace '/usr/share' "$out/share"
144
145 substituteInPlace packaging/linux/sunshine.desktop \
146 --replace '@PROJECT_NAME@' 'Sunshine'
147
148 # add FindFFMPEG to source tree
149 cp ${findFfmpeg} cmake/FindFFMPEG.cmake
150 '';
151
152 preBuild = ''
153 # copy node_modules where they can be picked up by build
154 mkdir -p ../node_modules
155 cp -r ${ui}/node_modules/* ../node_modules
156 '';
157
158 # allow Sunshine to find libvulkan
159 postFixup = lib.optionalString cudaSupport ''
160 wrapProgram $out/bin/sunshine \
161 --set LD_LIBRARY_PATH ${lib.makeLibraryPath [ vulkan-loader ]}
162 '';
163
164 postInstall = ''
165 install -Dm644 ../packaging/linux/${pname}.desktop $out/share/applications/${pname}.desktop
166 '';
167
168 passthru.updateScript = ./updater.sh;
169
170 meta = with lib; {
171 description = "Sunshine is a Game stream host for Moonlight.";
172 homepage = "https://github.com/LizardByte/Sunshine";
173 license = licenses.gpl3Only;
174 maintainers = with maintainers; [ devusb ];
175 platforms = platforms.linux;
176 };
177}