From a9ba9beaaf12440a8a507a46005728788b2608ad Mon Sep 17 00:00:00 2001 From: Ivan Kovalev Date: Sun, 2 Feb 2025 19:23:28 +0100 Subject: [PATCH 1/5] Add nix-shell to allow native build on NixOS --- documents/build-nixos/README.md | 14 +++ documents/build-nixos/shell.nix | 147 ++++++++++++++++++++++++++++++++ documents/building-linux.md | 8 +- 3 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 documents/build-nixos/README.md create mode 100644 documents/build-nixos/shell.nix diff --git a/documents/build-nixos/README.md b/documents/build-nixos/README.md new file mode 100644 index 00000000000..411821180dc --- /dev/null +++ b/documents/build-nixos/README.md @@ -0,0 +1,14 @@ + + +## 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. diff --git a/documents/build-nixos/shell.nix b/documents/build-nixos/shell.nix new file mode 100644 index 00000000000..ac22d4ce1bc --- /dev/null +++ b/documents/build-nixos/shell.nix @@ -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"} + ''; + +} diff --git a/documents/building-linux.md b/documents/building-linux.md index d9ae2e54cf9..b7bbbd88148 100644 --- a/documents/building-linux.md +++ b/documents/building-linux.md @@ -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 From fb6541d1bd950567ac9adc5156727be3a213f5fb Mon Sep 17 00:00:00 2001 From: Ivan Kovalev Date: Sun, 2 Feb 2025 20:14:16 +0100 Subject: [PATCH 2/5] Remove unnecessary README for nix. Move major comment to shell.nix --- documents/build-nixos/README.md | 14 -------------- documents/build-nixos/shell.nix => shell.nix | 2 ++ 2 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 documents/build-nixos/README.md rename documents/build-nixos/shell.nix => shell.nix (95%) diff --git a/documents/build-nixos/README.md b/documents/build-nixos/README.md deleted file mode 100644 index 411821180dc..00000000000 --- a/documents/build-nixos/README.md +++ /dev/null @@ -1,14 +0,0 @@ - - -## 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. diff --git a/documents/build-nixos/shell.nix b/shell.nix similarity index 95% rename from documents/build-nixos/shell.nix rename to shell.nix index ac22d4ce1bc..b5877305942 100644 --- a/documents/build-nixos/shell.nix +++ b/shell.nix @@ -1,3 +1,5 @@ +### 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, so we have to use a custom vulkan packages to build shadPS4. + with import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/606996d74f6e2a12635d41c1bf58bfc7ea3bb5ec.tar.gz") { }; let From fee783ce16dfa1439f025fbd060378e2099df67c Mon Sep 17 00:00:00 2001 From: Ivan Kovalev Date: Sun, 2 Feb 2025 20:17:33 +0100 Subject: [PATCH 3/5] Update path in building-linux.md --- documents/building-linux.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documents/building-linux.md b/documents/building-linux.md index b7bbbd88148..71e26e79298 100644 --- a/documents/building-linux.md +++ b/documents/building-linux.md @@ -40,7 +40,7 @@ sudo zypper install clang git cmake libasound2 libpulse-devel libsndio7 libjack- #### NixOS ``` -nix-shell documents/building-nixos/shell.nix +nix-shell shell.nix ``` #### Other Linux distributions From 4691b804bd082cf9df4c48ac29fafd1df236bcd7 Mon Sep 17 00:00:00 2001 From: Ivan Kovalev Date: Fri, 7 Feb 2025 16:47:34 +0100 Subject: [PATCH 4/5] Use cached nix packages from unstable channel --- shell.nix | 192 ++++++++++++++++-------------------------------------- 1 file changed, 55 insertions(+), 137 deletions(-) diff --git a/shell.nix b/shell.nix index b5877305942..66d61169eab 100644 --- a/shell.nix +++ b/shell.nix @@ -1,149 +1,67 @@ -### 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, so we have to use a custom vulkan packages to build shadPS4. +with import (fetchTarball "https://github.com/nixos/nixpkgs/archive/cfd19cdc54680956dc1816ac577abba6b58b901c.tar.gz") { }; -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 { +pkgs.mkShell { name = "shadps4-build-env"; + nativeBuildInputs = [ - clang - cmake - pkg-config - git + pkgs.llvmPackages_18.clang + pkgs.cmake + pkgs.pkg-config + pkgs.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 + pkgs.alsa-lib + pkgs.libpulseaudio + pkgs.openal + pkgs.openssl + pkgs.zlib + pkgs.libedit + pkgs.udev + pkgs.libevdev + pkgs.SDL2 + pkgs.jack2 + pkgs.sndio + pkgs.qt6.qtbase + pkgs.qt6.qttools + pkgs.qt6.qtmultimedia + + pkgs.vulkan-headers + pkgs.vulkan-utility-libraries + pkgs.vulkan-tools + + pkgs.ffmpeg + pkgs.fmt + pkgs.glslang + pkgs.libxkbcommon + pkgs.wayland + pkgs.xorg.libxcb + pkgs.xorg.xcbutil + pkgs.xorg.xcbutilkeysyms + pkgs.xorg.xcbutilwm + pkgs.sdl3 + pkgs.stb + pkgs.qt6.qtwayland + pkgs.wayland-protocols ]; + shellHook = '' + echo "Entering shadPS4 dev shell" 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 QT_PLUGIN_PATH="${pkgs.qt6.qtwayland}/lib/qt-6/plugins:${pkgs.qt6.qtbase}/lib/qt-6/plugins" + export QML2_IMPORT_PATH="${pkgs.qt6.qtbase}/lib/qt-6/qml" + export CMAKE_PREFIX_PATH="${pkgs.vulkan-headers}:$CMAKE_PREFIX_PATH" + + # OpenGL + export LD_LIBRARY_PATH="${ + pkgs.lib.makeLibraryPath [ + pkgs.libglvnd + pkgs.vulkan-tools + ] + }:$LD_LIBRARY_PATH" + + export LDFLAGS="-L${pkgs.llvmPackages_18.libcxx}/lib -lc++" export LC_ALL="C.UTF-8" export XAUTHORITY=${builtins.getEnv "XAUTHORITY"} ''; - } From 51866b9526a58c478df81bbd32cb57f5d9e29cc5 Mon Sep 17 00:00:00 2001 From: Ivan Kovalev Date: Fri, 7 Feb 2025 17:17:47 +0100 Subject: [PATCH 5/5] Add proper license to nix shell --- shell.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shell.nix b/shell.nix index 66d61169eab..cc9cc1f82b8 100644 --- a/shell.nix +++ b/shell.nix @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2024 shadPS4 Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later + with import (fetchTarball "https://github.com/nixos/nixpkgs/archive/cfd19cdc54680956dc1816ac577abba6b58b901c.tar.gz") { }; pkgs.mkShell {