nixpkgs/pkgs/servers/sunshine/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

217 lines
4.4 KiB
Nix
Raw Normal View History

2022-10-23 02:14:57 +00:00
{ lib
, stdenv
, fetchFromGitHub
, autoPatchelfHook
, autoAddDriverRunpath
2023-02-27 01:17:12 +00:00
, makeWrapper
2022-12-22 00:17:52 +00:00
, buildNpmPackage
2024-03-31 01:07:48 +00:00
, nixosTests
2022-10-23 02:14:57 +00:00
, cmake
, avahi
, libevdev
, libpulseaudio
, xorg
, libxcb
, openssl
, libopus
, boost
, pkg-config
, libdrm
, wayland
, wayland-scanner
2022-10-23 02:14:57 +00:00
, libffi
, libcap
, mesa
2022-12-22 00:17:52 +00:00
, curl
2023-10-21 16:38:35 +00:00
, pcre
, pcre2
2024-04-15 12:11:32 +00:00
, python3
2023-10-21 16:38:35 +00:00
, libuuid
, libselinux
, libsepol
, libthai
, libdatrie
, libxkbcommon
, libepoxy
2022-12-22 00:17:52 +00:00
, libva
, libvdpau
, libglvnd
2022-12-22 00:17:52 +00:00
, numactl
2023-02-27 01:17:12 +00:00
, amf-headers
2023-10-21 16:38:35 +00:00
, intel-media-sdk
2023-02-27 01:17:12 +00:00
, svt-av1
, vulkan-loader
2023-04-03 00:02:22 +00:00
, libappindicator
2023-10-21 16:38:35 +00:00
, libnotify
2024-03-07 01:35:58 +00:00
, miniupnpc
, config
, cudaSupport ? config.cudaSupport
2024-03-07 01:35:58 +00:00
, cudaPackages ? { }
2022-10-23 02:14:57 +00:00
}:
let
stdenv' = if cudaSupport then cudaPackages.backendStdenv else stdenv;
in
stdenv'.mkDerivation rec {
2022-10-23 02:14:57 +00:00
pname = "sunshine";
2024-04-25 00:18:07 +00:00
version = "0.23.1";
2022-10-23 02:14:57 +00:00
src = fetchFromGitHub {
owner = "LizardByte";
repo = "Sunshine";
rev = "v${version}";
hash = "sha256-D5ee5m2ZTKVqZDH07nzJuFEbZBQ4xW7m4nYnJQe0EaA=";
2022-10-23 02:14:57 +00:00
fetchSubmodules = true;
};
patches = [
# fix(upnp): support newer miniupnpc library (#2782)
# Manually cherry-picked on to 0.23.1.
./0001-fix-upnp-support-newer-miniupnpc-library-2782.patch
];
2024-03-07 01:35:58 +00:00
# build webui
2022-12-22 00:17:52 +00:00
ui = buildNpmPackage {
inherit src version;
pname = "sunshine-ui";
2024-04-25 00:18:07 +00:00
npmDepsHash = "sha256-9FuMtxTwrU9UIhZXQn/tmGN0IHZBdunV0cY/EElj4bA=";
2022-12-22 00:17:52 +00:00
2023-04-03 00:02:22 +00:00
# use generated package-lock.json as upstream does not provide one
2022-12-22 00:17:52 +00:00
postPatch = ''
cp ${./package-lock.json} ./package-lock.json
'';
installPhase = ''
mkdir -p $out
2024-03-07 01:35:58 +00:00
cp -r * $out/
2022-12-22 00:17:52 +00:00
'';
};
2022-10-23 02:14:57 +00:00
nativeBuildInputs = [
cmake
pkg-config
2024-04-15 12:11:32 +00:00
python3
2023-02-27 01:17:12 +00:00
makeWrapper
wayland-scanner
# Avoid fighting upstream's usage of vendored ffmpeg libraries
autoPatchelfHook
2022-10-23 02:14:57 +00:00
] ++ lib.optionals cudaSupport [
autoAddDriverRunpath
2022-10-23 02:14:57 +00:00
];
buildInputs = [
avahi
libevdev
libpulseaudio
xorg.libX11
libxcb
xorg.libXfixes
xorg.libXrandr
xorg.libXtst
2023-04-03 00:02:22 +00:00
xorg.libXi
2022-10-23 02:14:57 +00:00
openssl
libopus
boost
libdrm
wayland
libffi
libevdev
libcap
libdrm
2022-12-22 00:17:52 +00:00
curl
2023-10-21 16:38:35 +00:00
pcre
pcre2
libuuid
libselinux
libsepol
libthai
libdatrie
xorg.libXdmcp
libxkbcommon
libepoxy
2022-12-22 00:17:52 +00:00
libva
libvdpau
numactl
2022-10-23 02:14:57 +00:00
mesa
2023-02-27 01:17:12 +00:00
amf-headers
svt-av1
2023-04-03 00:02:22 +00:00
libappindicator
2023-10-21 16:38:35 +00:00
libnotify
2024-03-07 01:35:58 +00:00
miniupnpc
2022-10-23 02:14:57 +00:00
] ++ lib.optionals cudaSupport [
cudaPackages.cudatoolkit
2023-10-21 16:38:35 +00:00
] ++ lib.optionals stdenv.hostPlatform.isx86_64 [
intel-media-sdk
2022-10-23 02:14:57 +00:00
];
2022-12-22 00:17:52 +00:00
runtimeDependencies = [
avahi
mesa
xorg.libXrandr
libxcb
libglvnd
2022-12-22 00:17:52 +00:00
];
2022-10-23 02:14:57 +00:00
cmakeFlags = [
2022-12-22 00:17:52 +00:00
"-Wno-dev"
2024-03-17 20:19:52 +00:00
# upstream tries to use systemd and udev packages to find these directories in FHS; set the paths explicitly instead
(lib.cmakeFeature "UDEV_RULES_INSTALL_DIR" "lib/udev/rules.d")
(lib.cmakeFeature "SYSTEMD_USER_UNIT_INSTALL_DIR" "lib/systemd/user")
2022-10-23 02:14:57 +00:00
];
postPatch = ''
2024-03-17 20:19:52 +00:00
# remove upstream dependency on systemd and udev
substituteInPlace cmake/packaging/linux.cmake \
--replace-fail 'find_package(Systemd)' "" \
--replace-fail 'find_package(Udev)' ""
2023-04-03 00:02:22 +00:00
substituteInPlace packaging/linux/sunshine.desktop \
2024-03-17 20:19:52 +00:00
--subst-var-by PROJECT_NAME 'Sunshine' \
--subst-var-by PROJECT_DESCRIPTION 'Self-hosted game stream host for Moonlight' \
--replace-fail '/usr/bin/env systemctl start --u sunshine' 'sunshine'
substituteInPlace packaging/linux/sunshine.service.in \
--subst-var-by PROJECT_DESCRIPTION 'Self-hosted game stream host for Moonlight' \
--subst-var-by SUNSHINE_EXECUTABLE_PATH $out/bin/sunshine
2022-12-22 00:17:52 +00:00
'';
2022-10-23 02:14:57 +00:00
2022-12-22 00:17:52 +00:00
preBuild = ''
2024-03-07 01:35:58 +00:00
# copy webui where it can be picked up by build
cp -r ${ui}/build ../
2023-02-27 01:17:12 +00:00
'';
2024-04-25 00:18:07 +00:00
buildFlags = [
"sunshine"
];
2023-02-27 01:17:12 +00:00
# allow Sunshine to find libvulkan
postFixup = lib.optionalString cudaSupport ''
wrapProgram $out/bin/sunshine \
--set LD_LIBRARY_PATH ${lib.makeLibraryPath [ vulkan-loader ]}
2022-10-23 02:14:57 +00:00
'';
2024-04-25 00:18:07 +00:00
# redefine installPhase to avoid attempt to build webui
installPhase = ''
runHook preInstall
cmake --install .
runHook postInstall
'';
2023-04-03 00:02:22 +00:00
postInstall = ''
install -Dm644 ../packaging/linux/${pname}.desktop $out/share/applications/${pname}.desktop
'';
2024-03-31 01:07:48 +00:00
passthru = {
tests.sunshine = nixosTests.sunshine;
updateScript = ./updater.sh;
};
2023-04-03 00:01:56 +00:00
2022-10-23 02:14:57 +00:00
meta = with lib; {
2023-10-21 16:38:35 +00:00
description = "Sunshine is a Game stream host for Moonlight";
2022-12-22 00:17:52 +00:00
homepage = "https://github.com/LizardByte/Sunshine";
2022-10-23 02:14:57 +00:00
license = licenses.gpl3Only;
mainProgram = "sunshine";
2022-10-23 02:14:57 +00:00
maintainers = with maintainers; [ devusb ];
platforms = platforms.linux;
};
}