From 4de9053c05d80ed5bd30229fbf5a4938adcfe974 Mon Sep 17 00:00:00 2001 From: Luna <93695520+LunaisLazier@users.noreply.github.com> Date: Sat, 11 Jan 2025 13:14:07 -0600 Subject: [PATCH] Parity with Upstream towards Nix --- flake.nix | 26 +++++------- nix/README.md | 8 +--- nix/unwrapped.nix | 24 ++++++----- nix/wrapper.nix | 105 ++++++++++++++++++---------------------------- 4 files changed, 64 insertions(+), 99 deletions(-) diff --git a/flake.nix b/flake.nix index 2e53b1213..b1db6afc3 100644 --- a/flake.nix +++ b/flake.nix @@ -85,24 +85,18 @@ formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style); - overlays.default = - final: prev: - let - version = builtins.substring 0 8 self.lastModifiedDate or "dirty"; - in - { - shatteredprism-unwrapped = prev.callPackage ./nix/unwrapped.nix { - inherit - libnbtplusplus - nix-filter - self - version - ; - }; - - shatteredprism = final.callPackage ./nix/wrapper.nix { }; + overlays.default = final: prev: { + shatteredprism-unwrapped = prev.callPackage ./nix/unwrapped.nix { + inherit + libnbtplusplus + nix-filter + self + ; }; + shatteredprism = final.callPackage ./nix/wrapper.nix { }; + }; + packages = forAllSystems ( system: let diff --git a/nix/README.md b/nix/README.md index df724b41e..5e8ab74c5 100644 --- a/nix/README.md +++ b/nix/README.md @@ -1,11 +1,5 @@ # Shattered Prism Nix Packaging -## Installing a stable release (nixpkgs) - -Shattered Prism is packaged in [nixpkgs](https://github.com/NixOS/nixpkgs/) since 22.11. - -See [Package variants](#package-variants) for a list of available packages. - ## Installing a development release (flake) We use [cachix](https://cachix.org/) to cache our development and release builds. @@ -205,7 +199,7 @@ nix-env -iA shatteredprism.shatteredprism ## Package variants -Both Nixpkgs and this repository offer the following packages: +This repository offers the following packages: - `shatteredprism` - The preferred build, wrapped with everything necessary to run the launcher and Minecraft - `shatteredprism-unwrapped` - A minimal build that allows for advanced customization of the launcher's runtime environment diff --git a/nix/unwrapped.nix b/nix/unwrapped.nix index 26b598e4e..74071d327 100644 --- a/nix/unwrapped.nix +++ b/nix/unwrapped.nix @@ -3,12 +3,13 @@ stdenv, cmake, cmark, - darwin, + apple-sdk_11, extra-cmake-modules, gamemode, ghc_filesystem, jdk17, kdePackages, + libnbtplusplus, ninja, nix-filter, self, @@ -17,16 +18,14 @@ zlib, msaClientID ? null, - gamemodeSupport ? stdenv.isLinux, - version, - libnbtplusplus, + gamemodeSupport ? stdenv.hostPlatform.isLinux, }: assert lib.assertMsg ( - gamemodeSupport -> stdenv.isLinux + gamemodeSupport -> stdenv.hostPlatform.isLinux ) "gamemodeSupport is only available on Linux."; stdenv.mkDerivation { pname = "shatteredprism-unwrapped"; - inherit version; + version = self.shortRev or self.dirtyShortRev or "unknown"; src = nix-filter.lib { root = self; @@ -65,20 +64,23 @@ stdenv.mkDerivation { tomlplusplus zlib ] - ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.apple_sdk.frameworks.Cocoa ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ apple-sdk_11 ] ++ lib.optional gamemodeSupport gamemode; - hardeningEnable = lib.optionals stdenv.isLinux [ "pie" ]; + hardeningEnable = lib.optionals stdenv.hostPlatform.isLinux [ "pie" ]; cmakeFlags = - [ (lib.cmakeFeature "Launcher_BUILD_PLATFORM" "nixpkgs") ] + [ + # downstream branding + (lib.cmakeFeature "Launcher_BUILD_PLATFORM" "nixpkgs") + ] ++ lib.optionals (msaClientID != null) [ (lib.cmakeFeature "Launcher_MSA_CLIENT_ID" (toString msaClientID)) ] ++ lib.optionals (lib.versionOlder kdePackages.qtbase.version "6") [ (lib.cmakeFeature "Launcher_QT_VERSION_MAJOR" "5") ] - ++ lib.optionals stdenv.isDarwin [ + ++ lib.optionals stdenv.hostPlatform.isDarwin [ # we wrap our binary manually (lib.cmakeFeature "INSTALL_BUNDLE" "nodeps") # disable built-in updater @@ -100,7 +102,7 @@ stdenv.mkDerivation { homepage = "https://github.com/lunaislazier/ShatteredPrism"; license = lib.licenses.gpl3Only; maintainers = with lib.maintainers; [ - lunaislazier + evan-goode ]; mainProgram = "shatteredprism"; platforms = lib.platforms.linux ++ lib.platforms.darwin; diff --git a/nix/wrapper.nix b/nix/wrapper.nix index 7bbbd4a63..f3c7246e2 100644 --- a/nix/wrapper.nix +++ b/nix/wrapper.nix @@ -1,56 +1,51 @@ { - lib, - stdenv, - symlinkJoin, - shatteredprism-unwrapped, addDriverRunpath, + alsa-lib, flite, gamemode, - glfw, - glfw-wayland-minecraft, - glxinfo, - jdk8, + glfw3-minecraft, jdk17, jdk21, + jdk8, kdePackages, + lib, libGL, + libX11, + libXcursor, + libXext, + libXrandr, + libXxf86vm, + libjack2, libpulseaudio, libusb1, - makeWrapper, + mesa-demos, openal, pciutils, + pipewire, + shatteredprism-unwrapped, + stdenv, + symlinkJoin, udev, vulkan-loader, - xorg, + xrandr, additionalLibs ? [ ], additionalPrograms ? [ ], - controllerSupport ? stdenv.isLinux, - gamemodeSupport ? stdenv.isLinux, + controllerSupport ? stdenv.hostPlatform.isLinux, + gamemodeSupport ? stdenv.hostPlatform.isLinux, jdks ? [ jdk21 jdk17 jdk8 ], msaClientID ? null, - textToSpeechSupport ? stdenv.isLinux, - # Adds `glfw-wayland-minecraft` to `LD_LIBRARY_PATH` - # when launched on wayland, allowing for the game to be run natively. - # Make sure to enable "Use system installation of GLFW" in instance settings - # for this to take effect - # - # Warning: This build of glfw may be unstable, and the launcher - # itself can take slightly longer to start - withWaylandGLFW ? false, + textToSpeechSupport ? stdenv.hostPlatform.isLinux, }: assert lib.assertMsg ( - controllerSupport -> stdenv.isLinux + controllerSupport -> stdenv.hostPlatform.isLinux ) "controllerSupport only has an effect on Linux."; assert lib.assertMsg ( - textToSpeechSupport -> stdenv.isLinux + textToSpeechSupport -> stdenv.hostPlatform.isLinux ) "textToSpeechSupport only has an effect on Linux."; -assert lib.assertMsg ( - withWaylandGLFW -> stdenv.isLinux -) "withWaylandGLFW is only available on Linux."; let shatteredprism' = shatteredprism-unwrapped.override { inherit msaClientID gamemodeSupport; }; in @@ -60,13 +55,7 @@ symlinkJoin { paths = [ shatteredprism' ]; - nativeBuildInputs = - [ - kdePackages.wrapQtAppsHook - ] - # purposefully using a shell wrapper here for variable expansion - # see https://github.com/NixOS/nixpkgs/issues/172583 - ++ lib.optional withWaylandGLFW makeWrapper; + nativeBuildInputs = [ kdePackages.wrapQtAppsHook ]; buildInputs = [ @@ -74,30 +63,18 @@ symlinkJoin { kdePackages.qtsvg ] ++ lib.optional ( - lib.versionAtLeast kdePackages.qtbase.version "6" && stdenv.isLinux + lib.versionAtLeast kdePackages.qtbase.version "6" && stdenv.hostPlatform.isLinux ) kdePackages.qtwayland; - env = { - waylandPreExec = lib.optionalString withWaylandGLFW '' - if [ -n "$WAYLAND_DISPLAY" ]; then - export LD_LIBRARY_PATH=${lib.getLib glfw-wayland-minecraft}/lib:"$LD_LIBRARY_PATH" - fi - ''; - }; - - postBuild = - lib.optionalString withWaylandGLFW '' - qtWrapperArgs+=(--run "$waylandPreExec") - '' - + '' - wrapQtAppsHook - ''; + postBuild = '' + wrapQtAppsHook + ''; qtWrapperArgs = let runtimeLibs = [ - stdenv.cc.cc.lib + (lib.getLib stdenv.cc.cc) ## native versions glfw3-minecraft openal @@ -106,19 +83,19 @@ symlinkJoin { alsa-lib libjack2 libpulseaudio - libGL - openal - stdenv.cc.cc.lib + pipewire - vulkan-loader # VulkanMod's lwjgl + ## glfw + libGL + libX11 + libXcursor + libXext + libXrandr + libXxf86vm udev # oshi - xorg.libX11 - xorg.libXext - xorg.libXcursor - xorg.libXrandr - xorg.libXxf86vm + vulkan-loader # VulkanMod's lwjgl ] ++ lib.optional textToSpeechSupport flite ++ lib.optional gamemodeSupport gamemode.lib @@ -126,16 +103,14 @@ symlinkJoin { ++ additionalLibs; runtimePrograms = [ - glxinfo + mesa-demos pciutils # need lspci - xorg.xrandr # needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128 + xrandr # needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128 ] ++ additionalPrograms; in - [ - "--prefix SHATTEREDPRISM_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks}" - ] - ++ lib.optionals stdenv.isLinux [ + [ "--prefix SHATTEREDPRISM_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks}" ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ "--set LD_LIBRARY_PATH ${addDriverRunpath.driverLink}/lib:${lib.makeLibraryPath runtimeLibs}" "--prefix PATH : ${lib.makeBinPath runtimePrograms}" ];