From 875727fbb7829e6066c6f537821a2b7321964b5c Mon Sep 17 00:00:00 2001 From: Evan Goode Date: Sat, 20 Jul 2024 18:40:32 -0400 Subject: [PATCH] nix: sync changes from nixpkgs Brings in changes from the Prism Launcher derivation(s) in nixpkgs, notably from https://github.com/NixOS/nixpkgs/pull/321851 and https://github.com/NixOS/nixpkgs/pull/303880 Signed-off-by: Evan Goode --- nix/dev.nix | 2 +- nix/distribution.nix | 32 +--------- nix/pkg/default.nix | 105 ++++++++++++++++++++----------- nix/pkg/wrapper.nix | 147 ++++++++++++++++++++++++++++--------------- 4 files changed, 169 insertions(+), 117 deletions(-) diff --git a/nix/dev.nix b/nix/dev.nix index f79483179..08bbeea3f 100644 --- a/nix/dev.nix +++ b/nix/dev.nix @@ -19,7 +19,7 @@ }; }; - tools.clang-tools = lib.mkForce pkgs.clang-tools_16; + tools.clang-tools = lib.mkForce pkgs.clang-tools_18; }; devShells.default = pkgs.mkShell { diff --git a/nix/distribution.nix b/nix/distribution.nix index b642125d4..8981fa6af 100644 --- a/nix/distribution.nix +++ b/nix/distribution.nix @@ -13,8 +13,6 @@ in { inherit (ourPackages) - fjordlauncher-qt5-unwrapped - fjordlauncher-qt5 fjordlauncher-unwrapped fjordlauncher ; @@ -25,37 +23,11 @@ flake = { overlays.default = final: prev: let version = builtins.substring 0 8 self.lastModifiedDate or "dirty"; - - filteredSelf = inputs.nix-filter.lib.filter { - root = ../.; - include = [ - "buildconfig" - "cmake" - "launcher" - "libraries" - "program_info" - "tests" - ../COPYING.md - ../CMakeLists.txt - ]; - }; - - # common args for prismlauncher evaluations - unwrappedArgs = { - self = filteredSelf; - + in { + fjordlauncher-unwrapped = prev.callPackage ./pkg { inherit (inputs) libnbtplusplus; - inherit ((final.darwin or prev.darwin).apple_sdk.frameworks) Cocoa; inherit version; }; - in { - fjordlauncher-qt5-unwrapped = prev.libsForQt5.callPackage ./pkg unwrappedArgs; - - fjordlauncher-qt5 = prev.libsForQt5.callPackage ./pkg/wrapper.nix { - fjordlauncher-unwrapped = final.fjordlauncher-qt5-unwrapped; - }; - - fjordlauncher-unwrapped = prev.qt6Packages.callPackage ./pkg unwrappedArgs; fjordlauncher = prev.qt6Packages.callPackage ./pkg/wrapper.nix { inherit (final) fjordlauncher-unwrapped; diff --git a/nix/pkg/default.nix b/nix/pkg/default.nix index 019e6983a..7f6aacdfa 100644 --- a/nix/pkg/default.nix +++ b/nix/pkg/default.nix @@ -1,74 +1,105 @@ { lib, stdenv, - canonicalize-jars-hook, cmake, cmark, - Cocoa, - ninja, - jdk17, - zlib, - qtbase, - quazip, + darwin, extra-cmake-modules, - tomlplusplus, - ghc_filesystem, gamemode, + ghc_filesystem, + jdk17, + kdePackages, + ninja, + stripJavaArchivesHook, + tomlplusplus, + zlib, msaClientID ? null, gamemodeSupport ? stdenv.isLinux, - self, version, libnbtplusplus, }: -assert lib.assertMsg (stdenv.isLinux || !gamemodeSupport) "gamemodeSupport is only available on Linux"; - stdenv.mkDerivation rec { +assert lib.assertMsg ( + gamemodeSupport -> stdenv.isLinux +) "gamemodeSupport is only available on Linux."; + stdenv.mkDerivation { pname = "fjordlauncher-unwrapped"; inherit version; - src = lib.cleanSource self; + src = lib.fileset.toSource { + root = ../../.; + fileset = lib.fileset.unions (map (fileName: ../../${fileName}) [ + "buildconfig" + "cmake" + "launcher" + "libraries" + "program_info" + "tests" + "COPYING.md" + "CMakeLists.txt" + ]); + }; + + postUnpack = '' + rm -rf source/libraries/libnbtplusplus + ln -s ${libnbtplusplus} source/libraries/libnbtplusplus + ''; + + nativeBuildInputs = [ + cmake + ninja + extra-cmake-modules + jdk17 + stripJavaArchivesHook + ]; - nativeBuildInputs = [extra-cmake-modules cmake jdk17 ninja canonicalize-jars-hook]; buildInputs = [ - qtbase - zlib - quazip + cmark ghc_filesystem + kdePackages.qtbase + kdePackages.qtnetworkauth + kdePackages.quazip tomlplusplus - cmark + zlib ] - ++ lib.optional gamemodeSupport gamemode - ++ lib.optionals stdenv.isDarwin [Cocoa]; + ++ lib.optionals stdenv.isDarwin [darwin.apple_sdk.frameworks.Cocoa] + ++ lib.optional gamemodeSupport gamemode; hardeningEnable = lib.optionals stdenv.isLinux ["pie"]; cmakeFlags = [ - "-DLauncher_BUILD_PLATFORM=nixpkgs" + (lib.cmakeFeature "Launcher_BUILD_PLATFORM" "nixpkgs") ] - ++ lib.optionals (msaClientID != null) ["-DLauncher_MSA_CLIENT_ID=${msaClientID}"] - ++ lib.optionals (lib.versionOlder qtbase.version "6") ["-DLauncher_QT_VERSION_MAJOR=5"] - ++ lib.optionals stdenv.isDarwin ["-DINSTALL_BUNDLE=nodeps" "-DMACOSX_SPARKLE_UPDATE_FEED_URL=''"]; - - postUnpack = '' - rm -rf source/libraries/libnbtplusplus - ln -s ${libnbtplusplus} source/libraries/libnbtplusplus - ''; + ++ 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 [ + # we wrap our binary manually + (lib.cmakeFeature "INSTALL_BUNDLE" "nodeps") + # disable built-in updater + (lib.cmakeFeature "MACOSX_SPARKLE_UPDATE_FEED_URL" "''") + (lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}/Applications/") + ]; dontWrapQtApps = true; - meta = with lib; { - mainProgram = "fjordlauncher"; - homepage = "https://github.com/unmojang/FjordLauncher/"; - description = "A free, open source launcher for Minecraft"; + meta = { + description = "Prism Launcher fork with support for alternative auth servers"; longDescription = '' Allows you to have multiple, separate instances of Minecraft (each with their own mods, texture packs, saves, etc) and helps you manage them and their associated options with a simple interface. ''; - platforms = with platforms; linux ++ darwin; - changelog = "https://github.com/unmojang/FjordLauncher/releases/tag/${version}"; - license = licenses.gpl3Only; - maintainers = with maintainers; [evan-goode]; + homepage = "https://fjordlauncher.org/"; + license = lib.licenses.gpl3Only; + maintainers = with lib.maintainers; [ + evan-goode + ]; + mainProgram = "fjordlauncher"; + platforms = lib.platforms.linux ++ lib.platforms.darwin; }; } diff --git a/nix/pkg/wrapper.nix b/nix/pkg/wrapper.nix index 5ff7901c2..3df31f7dc 100644 --- a/nix/pkg/wrapper.nix +++ b/nix/pkg/wrapper.nix @@ -3,94 +3,143 @@ stdenv, symlinkJoin, fjordlauncher-unwrapped, - wrapQtAppsHook, addOpenGLRunpath, - qtbase, # needed for wrapQtAppsHook - qtsvg, - qtwayland, - xorg, - libpulseaudio, - libGL, + flite, + gamemode, glfw, - openal, + glfw-wayland-minecraft, + glxinfo, jdk8, jdk17, jdk21, - gamemode, - flite, - mesa-demos, - udev, + kdePackages, + libGL, + libpulseaudio, libusb1, - msaClientID ? null, - gamemodeSupport ? stdenv.isLinux, - textToSpeechSupport ? stdenv.isLinux, - controllerSupport ? stdenv.isLinux, - jdks ? [jdk21 jdk17 jdk8], + makeWrapper, + openal, + pciutils, + udev, + vulkan-loader, + xorg, additionalLibs ? [], additionalPrograms ? [], -}: let - fjordlauncherFinal = fjordlauncher-unwrapped.override { - inherit msaClientID gamemodeSupport; - }; + controllerSupport ? stdenv.isLinux, + gamemodeSupport ? stdenv.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, +}: +assert lib.assertMsg ( + controllerSupport -> stdenv.isLinux +) "controllerSupport only has an effect on Linux."; +assert lib.assertMsg ( + textToSpeechSupport -> stdenv.isLinux +) "textToSpeechSupport only has an effect on Linux."; +assert lib.assertMsg ( + withWaylandGLFW -> stdenv.isLinux +) "withWaylandGLFW is only available on Linux."; let + fjordlauncher' = fjordlauncher-unwrapped.override {inherit msaClientID gamemodeSupport;}; in symlinkJoin { - name = "fjordlauncher-${fjordlauncherFinal.version}"; + name = "fjordlauncher-${fjordlauncher'.version}"; - paths = [fjordlauncherFinal]; + paths = [fjordlauncher']; - nativeBuildInputs = [ - wrapQtAppsHook - ]; + nativeBuildInputs = + [kdePackages.wrapQtAppsHook] + # purposefully using a shell wrapper here for variable expansion + # see https://github.com/NixOS/nixpkgs/issues/172583 + ++ lib.optional withWaylandGLFW makeWrapper; buildInputs = [ - qtbase - qtsvg + kdePackages.qtbase + kdePackages.qtsvg ] - ++ lib.optional (lib.versionAtLeast qtbase.version "6" && stdenv.isLinux) qtwayland; + ++ lib.optional ( + lib.versionAtLeast kdePackages.qtbase.version "6" && stdenv.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 = '' - wrapQtAppsHook - ''; + postBuild = + lib.optionalString withWaylandGLFW '' + qtWrapperArgs+=(--run "$waylandPreExec") + '' + + '' + wrapQtAppsHook + ''; qtWrapperArgs = let runtimeLibs = - (with xorg; [ - libX11 - libXext - libXcursor - libXrandr - libXxf86vm - ]) - ++ [ + [ # lwjgl + glfw libpulseaudio libGL - glfw openal stdenv.cc.cc.lib - # oshi - udev + vulkan-loader # VulkanMod's lwjgl + + udev # oshi + + xorg.libX11 + xorg.libXext + xorg.libXcursor + xorg.libXrandr + xorg.libXxf86vm ] - ++ lib.optional gamemodeSupport gamemode.lib ++ lib.optional textToSpeechSupport flite + ++ lib.optional gamemodeSupport gamemode.lib ++ lib.optional controllerSupport libusb1 ++ additionalLibs; runtimePrograms = [ - xorg.xrandr - mesa-demos # need glxinfo + glxinfo + pciutils # need lspci + xorg.xrandr # needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128 ] ++ additionalPrograms; in - ["--prefix FJORDLAUNCHER_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks}"] + ["--prefix fjordLAUNCHER_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks}"] ++ lib.optionals stdenv.isLinux [ "--set LD_LIBRARY_PATH ${addOpenGLRunpath.driverLink}/lib:${lib.makeLibraryPath runtimeLibs}" - # xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128 "--prefix PATH : ${lib.makeBinPath runtimePrograms}" ]; - inherit (fjordlauncherFinal) meta; + meta = { + inherit + (fjordlauncher'.meta) + description + longDescription + homepage + changelog + license + maintainers + mainProgram + platforms + ; + }; }