From 320f140f52339d39c4eadd3a6e33f03b74b03ea8 Mon Sep 17 00:00:00 2001 From: Danilo Reyes Date: Wed, 29 May 2024 09:35:16 -0600 Subject: [PATCH] minecraft --- home-manager/default.nix | 2 +- modules/apps/gaming.nix | 9 ++- pkgs/polymc/default.nix | 140 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 pkgs/polymc/default.nix diff --git a/home-manager/default.nix b/home-manager/default.nix index 119746a..c9ef769 100644 --- a/home-manager/default.nix +++ b/home-manager/default.nix @@ -63,7 +63,7 @@ fd --full-path $NIXOSDIR -e nix -x nixfmt \; sudo nixos-rebuild switch \ --flake "$NIXOSDIR/#$HOSTNAME" \ - & nom + | nom } ''; }; diff --git a/modules/apps/gaming.nix b/modules/apps/gaming.nix index 9f16154..eca14b7 100644 --- a/modules/apps/gaming.nix +++ b/modules/apps/gaming.nix @@ -1,4 +1,6 @@ -{ config, lib, pkgs, ... }: { +{ config, lib, pkgs, ... }: +let polymc = pkgs.callPackage ../../pkgs/polymc/default.nix { }; +in { options.my.apps.gaming.enable = lib.mkEnableOption "enable"; config = lib.mkIf config.my.apps.gaming.enable { programs = { @@ -17,9 +19,10 @@ gamemode # optimizes linux to have better gaming performance heroic # install epic games protonup-qt # update proton-ge - # grapejuice # roblox manager - # minecraft # minecraft official launcher + minecraft # minecraft official launcher + polymc # minecraft launcher with mod support ns-usbloader # load games into my switch + # grapejuice # roblox manager # emulators rpcs3 # ps3 emulator diff --git a/pkgs/polymc/default.nix b/pkgs/polymc/default.nix new file mode 100644 index 0000000..9d347ef --- /dev/null +++ b/pkgs/polymc/default.nix @@ -0,0 +1,140 @@ +{ stdenv, lib, fetchFromGitHub, cmake, ninja, jdk21, ghc_filesystem, zlib, file +, xorg, libpulseaudio, openal, qt6, glfw, pciutils, udev, glxinfo, qt6Packages +, libGL, flite, addOpenGLRunpath, vulkan-loader, msaClientID ? null +, extra-cmake-modules, makeWrapper, gamemode, mangohud, glfw-wayland-minecraft +, writeShellScript }: + +let + polymc = let + binpath = lib.makeBinPath ([ xorg.xrandr glxinfo pciutils ]); + + libpath = with xorg; + lib.makeLibraryPath ([ + libX11 + libXext + libXcursor + libXrandr + libXxf86vm + libpulseaudio + libGL + vulkan-loader + glfw + openal + udev + flite + stdenv.cc.cc.lib + ]); + + gameLibraryPath = libpath + ":${addOpenGLRunpath.driverLink}/lib"; + + in stdenv.mkDerivation rec { + pname = "polymc" + + (lib.optionalString ((lib.versions.major qt6.qtbase.version) == "5") + "-qt5"); + version = "6.1"; + + src = fetchFromGitHub { + owner = "PolyMC"; + repo = "PolyMC"; + rev = version; + sha256 = "sha256-AOy13zAWQ0CtsX9z1M+fxH7Sh/QSFy7EdQ/fD9yUYc8="; + fetchSubmodules = true; + }; + dontWrapQtApps = true; + nativeBuildInputs = [ + cmake + extra-cmake-modules + ninja + jdk21 + qt6.wrapQtAppsHook + file + ghc_filesystem + ]; + buildInputs = [ + qt6.qtbase + qt6.qtsvg + qt6.qtcharts + qt6.qtwayland + qt6Packages.quazip + zlib + ]; + + cmakeFlags = [ + "-GNinja" + "-DLauncher_QT_VERSION_MAJOR=${lib.versions.major qt6.qtbase.version}" + ] ++ lib.optionals (msaClientID != null) + [ "-DLauncher_MSA_CLIENT_ID=${msaClientID}" ]; + + postPatch = '' + # hardcode jdk paths + substituteInPlace launcher/java/JavaUtils.cpp \ + --replace 'scanJavaDir("/usr/lib/jvm")' 'javas.append("${jdk21}/lib/openjdk/bin/java")' + ''; + + postFixup = '' + # xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128 + wrapQtApp $out/bin/polymc \ + --suffix LD_LIBRARY_PATH : "${gameLibraryPath}" \ + --suffix PATH : "${binpath}" \ + --set-default ALSOFT_DRIVERS "pulse" + ''; + passthru = { + + wrap = { extraJDKs ? [ ], extraPaths ? [ ], extraLibs ? [ ] + , withWaylandGLFW ? false, withMangohud ? true, withGamemode ? true }: + stdenv.mkDerivation rec { + pname = "${polymc.pname}-wrapped"; + version = polymc.version; + libsPath = (lib.makeLibraryPath + (extraLibs ++ lib.optional withGamemode gamemode.lib)) + + lib.optionalString withMangohud "${mangohud + "/lib/mangohud"}"; + binsPath = + lib.makeBinPath (extraPaths ++ lib.optional withMangohud mangohud); + + waylandPreExec = writeShellScript "waylandGLFW" '' + if [ -n "$WAYLAND_DISPLAY" ]; then + export LD_LIBRARY_PATH=${ + lib.getLib glfw-wayland-minecraft + }/lib:"$LD_LIBRARY_PATH" + fi + ''; + src = polymc; + nativeBuildInputs = [ makeWrapper ]; + phases = [ "installPhase" "fixupPhase" ]; + installPhase = '' + mkdir -p $out/bin + ln -s $src/bin/polymc $out/bin/polymc + ln -s $src/share $out/share + ''; + + postFixup = let javaPaths = lib.makeSearchPath "bin/java" (extraJDKs); + in '' + wrapProgram $out/bin/polymc \ + --suffix LD_LIBRARY_PATH : "${libsPath}" \ + --suffix POLYMC_JAVA_PATHS : "${javaPaths}" \ + --suffix PATH : "${binsPath}" ${ + lib.optionalString withWaylandGLFW "--run ${waylandPreExec}" + } + + ''; + + preferLocalBuild = true; + meta = polymc.meta; + + }; + }; + meta = with lib; { + homepage = "https://polymc.org/"; + downloadPage = "https://polymc.org/download/"; + changelog = "https://github.com/PolyMC/PolyMC/releases"; + description = "A free, open source launcher for Minecraft"; + 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 = [ "x86_64-linux" ]; + license = licenses.gpl3Only; + }; + }; +in polymc