Add nix-shell to allow native build on NixOS

This commit is contained in:
Ivan Kovalev 2025-02-02 19:23:28 +01:00
parent 1d8c607c15
commit a9ba9beaaf
3 changed files with 168 additions and 1 deletions

View File

@ -0,0 +1,14 @@
<!--
SPDX-FileCopyrightText: 2024 shadPS4 Emulator Project
SPDX-License-Identifier: GPL-2.0-or-later
-->
## Why do we need custom packages?
Because vulkan packages in official nix repo are still using version 1.3.296.0 while 1.4.305 or 1.4.304.0 is required for this package - we have to use a custom nix-shell to build shadPS4.
You can also use stagging branch, but in that case all packages would have to be rebuild and that takes hours, to mitigate this issue we're only using custom vulkan packages which don't have too many dependencies.
## When will we be able to use packages from official repo?
Once https://github.com/NixOS/nixpkgs/pull/373969 will reach unstable branch we should be able to use packages from nixpkgs repo.

View File

@ -0,0 +1,147 @@
with import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/606996d74f6e2a12635d41c1bf58bfc7ea3bb5ec.tar.gz") { };
let
vulkanLoaderCustom = pkgs.stdenv.mkDerivation rec {
pname = "vulkan-loader";
version = "1.4.305";
src = fetchFromGitHub {
owner = "KhronosGroup";
repo = "Vulkan-Loader";
rev = "v${version}";
hash = "sha256-nAxb2WH4FUNyZ0daO1lEcuuIbqLTjNDsc95m3NIY8F8=";
};
nativeBuildInputs = [ cmake pkg-config ];
buildInputs = [ vulkanHeadersCustom ]
++ lib.optionals stdenv.hostPlatform.isLinux [ xorg.libX11 xorg.libxcb xorg.libXrandr wayland ];
cmakeFlags = [ "-DCMAKE_INSTALL_INCLUDEDIR=${vulkanHeadersCustom}/include" ]
++ lib.optional stdenv.hostPlatform.isDarwin "-DSYSCONFDIR=${moltenvk}/share"
++ lib.optional stdenv.hostPlatform.isLinux "-DSYSCONFDIR=${addDriverRunpath.driverLink}/share"
++ lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) "-DUSE_GAS=OFF";
outputs = [ "out" "dev" ];
doInstallCheck = true;
installCheckPhase = ''
vulkan_path="${vulkanHeadersCustom}/include"
stripped_path="''${vulkan_path#/nix/store/}"
grep -q "$stripped_path" $dev/lib/pkgconfig/vulkan.pc || {
echo vulkanHeadersCustom include directory not found in pkg-config file
exit 1
}
'';
passthru = {
tests.pkg-config = testers.hasPkgConfigModules {
package = finalAttrs.finalPackage;
};
};
};
vulkanUtilsCustom = pkgs.stdenv.mkDerivation rec {
pname = "vulkan-utility-libraries";
version = "1.4.305";
src = fetchFromGitHub {
owner = "KhronosGroup";
repo = "Vulkan-Utility-Libraries";
rev = "vulkan-sdk-${version}";
hash = "sha256-YBket/4gsAkkr1eTQXz8lXGyQHtY5mm8jLPKAqSaawM=";
};
nativeBuildInputs = [
cmake
python3
];
buildInputs = [ vulkanHeadersCustom ];
};
vulkanHeadersCustom = pkgs.stdenv.mkDerivation rec {
pname = "vulkan-headers";
version = "1.4.305";
src = pkgs.fetchFromGitHub {
owner = "KhronosGroup";
repo = "Vulkan-Headers";
rev = "v${version}";
hash = "sha256-r5tgUxu+ZGzxBGAfLxX1bW4YshRdqCwxVQJsoQrtY/Y=";
};
cmakeFlags = lib.optionals stdenv.hostPlatform.isDarwin [ "-DVULKAN_HEADERS_ENABLE_MODULE=OFF" ];
nativeBuildInputs = [
pkgs.cmake
pkgs.ninja
];
};
llvmPackages = pkgs.llvmPackages_18;
overlay = self: super: {
vulkan-headers = vulkanHeadersCustom;
vulkan-utility-libraries = vulkanUtilsCustom;
vulkan-loader = vulkanLoaderCustom;
};
in
with import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/606996d74f6e2a12635d41c1bf58bfc7ea3bb5ec.tar.gz") { overlays = [ overlay ]; };
llvmPackages.stdenv.mkDerivation {
name = "shadps4-build-env";
nativeBuildInputs = [
clang
cmake
pkg-config
git
];
buildInputs = [
alsa-lib
libpulseaudio
openal
openssl
zlib
libedit
udev
libevdev
SDL2
jack2
sndio
qt6.qtbase
qt6.qttools
qt6.qtmultimedia
vulkanHeadersCustom
vulkanUtilsCustom
ffmpeg
fmt
glslang
libxkbcommon
wayland
xorg.libxcb
xorg.xcbutil
xorg.xcbutilkeysyms
xorg.xcbutilwm
sdl3
stb
qt6.qtwayland
wayland
wayland-protocols
libxkbcommon
];
shellHook = ''
export QT_QPA_PLATFORM="wayland"
export QT_PLUGIN_PATH="${qt6.qtwayland}/lib/qt-6/plugins:${qt6.qtbase}/lib/qt-6/plugins"
export QML2_IMPORT_PATH="${qt6.qtbase}/lib/qt-6/qml"
export CMAKE_PREFIX_PATH="${vulkanHeadersCustom}:$CMAKE_PREFIX_PATH"
# NVIDIA/OpenGL
export LD_LIBRARY_PATH="${lib.makeLibraryPath [ libglvnd ]}:$LD_LIBRARY_PATH"
export QT_PLUGIN_PATH="${qt6.qtbase}/lib/qt-6/plugins"
export QT_QPA_PLATFORM="xcb"
export LDFLAGS="-L${llvmPackages.libcxx}/lib -lc++"
export LC_ALL="C.UTF-8"
export XAUTHORITY=${builtins.getEnv "XAUTHORITY"}
'';
}

View File

@ -37,6 +37,12 @@ sudo pacman -S base-devel clang git cmake sndio jack2 openal qt6-base qt6-declar
sudo zypper install clang git cmake libasound2 libpulse-devel libsndio7 libjack-devel openal-soft-devel libopenssl-devel zlib-devel libedit-devel systemd-devel libevdev-devel qt6-base-devel qt6-multimedia-devel qt6-svg-devel qt6-linguist-devel qt6-gui-private-devel vulkan-devel vulkan-validationlayers
```
#### NixOS
```
nix-shell documents/building-nixos/shell.nix
```
#### Other Linux distributions
You can try one of two methods:
@ -49,7 +55,7 @@ distrobox create --name archlinux --init --image archlinux:latest
```
and install the dependencies on that container as cited above.
This option is **highly recommended** for NixOS and distributions with immutable/atomic filesystems (example: Fedora Kinoite, SteamOS).
This option is **highly recommended** for distributions with immutable/atomic filesystems (example: Fedora Kinoite, SteamOS).
### Cloning