nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 autoPatchelfHook,
6 autoAddDriverRunpath,
7 makeWrapper,
8 buildNpmPackage,
9 nixosTests,
10 cmake,
11 avahi,
12 libevdev,
13 libpulseaudio,
14 libxtst,
15 libxrandr,
16 libxi,
17 libxfixes,
18 libxdmcp,
19 libx11,
20 libxcb,
21 openssl,
22 libopus,
23 boost,
24 pkg-config,
25 libdrm,
26 wayland,
27 wayland-scanner,
28 libffi,
29 libcap,
30 libgbm,
31 curl,
32 pcre,
33 pcre2,
34 python3,
35 libuuid,
36 libselinux,
37 libsepol,
38 libthai,
39 libdatrie,
40 libxkbcommon,
41 libepoxy,
42 libva,
43 libvdpau,
44 libglvnd,
45 numactl,
46 amf-headers,
47 svt-av1,
48 vulkan-loader,
49 libappindicator,
50 libnotify,
51 miniupnpc,
52 nlohmann_json,
53 config,
54 coreutils,
55 udevCheckHook,
56 cudaSupport ? config.cudaSupport,
57 cudaPackages ? { },
58}:
59let
60 stdenv' = if cudaSupport then cudaPackages.backendStdenv else stdenv;
61in
62stdenv'.mkDerivation (finalAttrs: {
63 pname = "sunshine";
64 version = "2025.924.154138";
65
66 src = fetchFromGitHub {
67 owner = "LizardByte";
68 repo = "Sunshine";
69 tag = "v${finalAttrs.version}";
70 hash = "sha256-QrPfZqd9pgufohUjxlTpO6V0v7B41UrXHZaESsFjZ48=";
71 fetchSubmodules = true;
72 };
73
74 # build webui
75 ui = buildNpmPackage {
76 inherit (finalAttrs) src version;
77 pname = "sunshine-ui";
78 npmDepsHash = "sha256-miRw5JGZ8L+CKnoZkCuVW+ptzFV3Dg21zuS9lqNeHro=";
79
80 # use generated package-lock.json as upstream does not provide one
81 postPatch = ''
82 cp ${./package-lock.json} ./package-lock.json
83 '';
84
85 installPhase = ''
86 runHook preInstall
87
88 mkdir -p "$out"
89 cp -a . "$out"/
90
91 runHook postInstall
92 '';
93 };
94
95 postPatch = # remove upstream dependency on systemd and udev
96 ''
97 substituteInPlace cmake/packaging/linux.cmake \
98 --replace-fail 'find_package(Systemd)' "" \
99 --replace-fail 'find_package(Udev)' ""
100 ''
101 # don't look for npm since we build webui separately
102 + ''
103 substituteInPlace cmake/targets/common.cmake \
104 --replace-fail 'find_program(NPM npm REQUIRED)' ""
105
106 substituteInPlace packaging/linux/dev.lizardbyte.app.Sunshine.desktop \
107 --subst-var-by PROJECT_NAME 'Sunshine' \
108 --subst-var-by PROJECT_DESCRIPTION 'Self-hosted game stream host for Moonlight' \
109 --subst-var-by SUNSHINE_DESKTOP_ICON 'sunshine' \
110 --subst-var-by CMAKE_INSTALL_FULL_DATAROOTDIR "$out/share" \
111 --replace-fail '/usr/bin/env systemctl start --u sunshine' 'sunshine'
112
113 substituteInPlace packaging/linux/sunshine.service.in \
114 --subst-var-by PROJECT_DESCRIPTION 'Self-hosted game stream host for Moonlight' \
115 --subst-var-by SUNSHINE_EXECUTABLE_PATH $out/bin/sunshine \
116 --replace-fail '/bin/sleep' '${lib.getExe' coreutils "sleep"}'
117 '';
118
119 nativeBuildInputs = [
120 cmake
121 pkg-config
122 python3
123 makeWrapper
124 wayland-scanner
125 # Avoid fighting upstream's usage of vendored ffmpeg libraries
126 autoPatchelfHook
127 ]
128 ++ lib.optionals cudaSupport [
129 autoAddDriverRunpath
130 cudaPackages.cuda_nvcc
131 (lib.getDev cudaPackages.cuda_cudart)
132 ];
133
134 buildInputs = [
135 avahi
136 libevdev
137 libpulseaudio
138 libx11
139 libxcb
140 libxfixes
141 libxrandr
142 libxtst
143 libxi
144 openssl
145 libopus
146 boost
147 libdrm
148 wayland
149 libffi
150 libevdev
151 libcap
152 libdrm
153 curl
154 pcre
155 pcre2
156 libuuid
157 libselinux
158 libsepol
159 libthai
160 libdatrie
161 libxdmcp
162 libxkbcommon
163 libepoxy
164 libva
165 libvdpau
166 numactl
167 libgbm
168 amf-headers
169 svt-av1
170 libappindicator
171 libnotify
172 miniupnpc
173 nlohmann_json
174 ]
175 ++ lib.optionals cudaSupport [
176 cudaPackages.cudatoolkit
177 cudaPackages.cuda_cudart
178 ];
179
180 runtimeDependencies = [
181 avahi
182 libgbm
183 libxrandr
184 libxcb
185 libglvnd
186 ];
187
188 cmakeFlags = [
189 "-Wno-dev"
190 # upstream tries to use systemd and udev packages to find these directories in FHS; set the paths explicitly instead
191 (lib.cmakeBool "UDEV_FOUND" true)
192 (lib.cmakeBool "SYSTEMD_FOUND" true)
193 (lib.cmakeFeature "UDEV_RULES_INSTALL_DIR" "lib/udev/rules.d")
194 (lib.cmakeFeature "SYSTEMD_USER_UNIT_INSTALL_DIR" "lib/systemd/user")
195 (lib.cmakeFeature "SYSTEMD_MODULES_LOAD_DIR" "lib/modules-load.d")
196 (lib.cmakeBool "BOOST_USE_STATIC" false)
197 (lib.cmakeBool "BUILD_DOCS" false)
198 (lib.cmakeFeature "SUNSHINE_PUBLISHER_NAME" "nixpkgs")
199 (lib.cmakeFeature "SUNSHINE_PUBLISHER_WEBSITE" "https://nixos.org")
200 (lib.cmakeFeature "SUNSHINE_PUBLISHER_ISSUE_URL" "https://github.com/NixOS/nixpkgs/issues")
201 ]
202 ++ lib.optionals (!cudaSupport) [
203 (lib.cmakeBool "SUNSHINE_ENABLE_CUDA" false)
204 ];
205
206 env = {
207 # needed to trigger CMake version configuration
208 BUILD_VERSION = "${finalAttrs.version}";
209 BRANCH = "master";
210 COMMIT = "";
211 };
212
213 # copy webui where it can be picked up by build
214 preBuild = ''
215 cp -r ${finalAttrs.ui}/build ../
216 '';
217
218 buildFlags = [
219 "sunshine"
220 ];
221
222 # redefine installPhase to avoid attempt to build webui
223 installPhase = ''
224 runHook preInstall
225
226 cmake --install .
227
228 runHook postInstall
229 '';
230
231 postInstall = ''
232 install -Dm644 ../packaging/linux/dev.lizardbyte.app.Sunshine.desktop $out/share/applications/dev.lizardbyte.app.Sunshine.desktop
233 '';
234
235 # allow Sunshine to find libvulkan
236 postFixup = lib.optionalString cudaSupport ''
237 wrapProgram $out/bin/sunshine \
238 --set LD_LIBRARY_PATH ${lib.makeLibraryPath [ vulkan-loader ]}
239 '';
240
241 doInstallCheck = true;
242
243 nativeInstallCheckInputs = [ udevCheckHook ];
244
245 passthru = {
246 tests.sunshine = nixosTests.sunshine;
247 updateScript = ./updater.sh;
248 };
249
250 meta = {
251 description = "Game stream host for Moonlight";
252 homepage = "https://github.com/LizardByte/Sunshine";
253 license = lib.licenses.gpl3Only;
254 mainProgram = "sunshine";
255 maintainers = with lib.maintainers; [ devusb ];
256 platforms = lib.platforms.linux;
257 };
258})