nixpkgs/pkgs/servers/sunshine/default.nix

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

195 lines
4.0 KiB
Nix
Raw Normal View History

2022-10-23 02:14:57 +00:00
{ lib
, stdenv
, fetchFromGitHub
2022-12-22 00:17:52 +00:00
, autoPatchelfHook
2023-02-27 01:17:12 +00:00
, makeWrapper
2022-12-22 00:17:52 +00:00
, buildNpmPackage
2022-10-23 02:14:57 +00:00
, cmake
, avahi
, libevdev
, libpulseaudio
, xorg
, libxcb
, openssl
, libopus
, boost
, pkg-config
, libdrm
, wayland
, libffi
, libcap
, mesa
2022-12-22 00:17:52 +00:00
, curl
2023-10-21 16:38:35 +00:00
, pcre
, pcre2
, 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-03-17 20:19:52 +00:00
version = "0.22.2";
2022-10-23 02:14:57 +00:00
src = fetchFromGitHub {
owner = "LizardByte";
repo = "Sunshine";
rev = "v${version}";
2024-03-17 20:19:52 +00:00
sha256 = "sha256-So8fX0XQoW2cdTWWENoE07EU6e8vvjeTpizLoaDTjeg=";
2022-10-23 02:14:57 +00:00
fetchSubmodules = true;
};
2024-03-07 01:35:58 +00:00
patches = [
# remove npm install as it needs internet access -- handled separately below
./dont-build-webui.patch
];
# build webui
2022-12-22 00:17:52 +00:00
ui = buildNpmPackage {
inherit src version;
pname = "sunshine-ui";
2024-03-17 20:19:52 +00:00
npmDepsHash = "sha256-0487ntbJZ20MZHezQ+Z3EJkidF3Dgoh/mynYwR7k/+I=";
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
2022-12-22 00:17:52 +00:00
autoPatchelfHook
2023-02-27 01:17:12 +00:00
makeWrapper
2022-10-23 02:14:57 +00:00
] ++ lib.optionals cudaSupport [
cudaPackages.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.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
'';
# 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
'';
2023-04-03 00:02:22 +00:00
postInstall = ''
install -Dm644 ../packaging/linux/${pname}.desktop $out/share/applications/${pname}.desktop
'';
2023-04-03 00:01:56 +00:00
passthru.updateScript = ./updater.sh;
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;
};
}