From fc81b81c26b64e051b494bf16e4fe3c694c0503d Mon Sep 17 00:00:00 2001 From: cidkidnix Date: Sat, 8 Jan 2022 01:33:26 -0600 Subject: [PATCH] Add nixos support --- flake.nix | 9 ++++ nix/polymc/0001-pick-latest-java-first.patch | 48 ++++++++++++++++++++ nix/polymc/default.nix | 47 +++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 flake.nix create mode 100644 nix/polymc/0001-pick-latest-java-first.patch create mode 100644 nix/polymc/default.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..1d9f8b643 --- /dev/null +++ b/flake.nix @@ -0,0 +1,9 @@ +{ + description = "PolyMC"; + + outputs = inputs: { + overlay = self: super: rec { + polymc = super.libsForQt5.callPackage ./nix/polymc {}; + }; + }; +} \ No newline at end of file diff --git a/nix/polymc/0001-pick-latest-java-first.patch b/nix/polymc/0001-pick-latest-java-first.patch new file mode 100644 index 000000000..a65dcbfd0 --- /dev/null +++ b/nix/polymc/0001-pick-latest-java-first.patch @@ -0,0 +1,48 @@ +From 44e1b2a19a869b907b40e56c85c8a47aa6c22097 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Mustafa=20=C3=87al=C4=B1=C5=9Fkan?= +Date: Tue, 22 Jun 2021 21:50:11 +0300 +Subject: [PATCH] pick latest java first + +--- + launcher/java/JavaInstallList.cpp | 4 ++-- + launcher/java/JavaUtils.cpp | 2 +- + 2 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/launcher/java/JavaInstallList.cpp b/launcher/java/JavaInstallList.cpp +index 0bded03c..40898e20 100644 +--- a/launcher/java/JavaInstallList.cpp ++++ b/launcher/java/JavaInstallList.cpp +@@ -120,8 +120,8 @@ void JavaInstallList::updateListData(QList versions) + + bool sortJavas(BaseVersionPtr left, BaseVersionPtr right) + { +- auto rleft = std::dynamic_pointer_cast(left); +- auto rright = std::dynamic_pointer_cast(right); ++ auto rleft = std::dynamic_pointer_cast(right); ++ auto rright = std::dynamic_pointer_cast(left); + return (*rleft) > (*rright); + } + +diff --git a/launcher/java/JavaUtils.cpp b/launcher/java/JavaUtils.cpp +index 5f004a10..6d633631 100644 +--- a/launcher/java/JavaUtils.cpp ++++ b/launcher/java/JavaUtils.cpp +@@ -350,7 +350,6 @@ QList JavaUtils::FindJavaPaths() + qDebug() << "Linux Java detection incomplete - defaulting to \"java\""; + + QList javas; +- javas.append(this->GetDefaultJava()->path); + auto scanJavaDir = [&](const QString & dirPath) + { + QDir dir(dirPath); +@@ -379,6 +378,7 @@ QList JavaUtils::FindJavaPaths() + // general locations used by distro packaging + scanJavaDir("/usr/lib/jvm"); + scanJavaDir("/usr/lib32/jvm"); ++ javas.append(this->GetDefaultJava()->path); + // javas stored in MultiMC's folder + scanJavaDir("java"); + return javas; +-- +2.31.1 + diff --git a/nix/polymc/default.nix b/nix/polymc/default.nix new file mode 100644 index 000000000..8f69f2740 --- /dev/null +++ b/nix/polymc/default.nix @@ -0,0 +1,47 @@ +{ lib, mkDerivation, fetchFromGitHub, cmake, jdk8, jdk, zlib, file, makeWrapper, xorg, libpulseaudio, qtbase, libGL, msaClientID ? "" }: + +let + libpath = with xorg; lib.makeLibraryPath [ libX11 libXext libXcursor libXrandr libXxf86vm libpulseaudio libGL ]; +in +mkDerivation rec { + pname = "polymc"; + version = "1.0.4"; + src = fetchFromGitHub { + owner = "PolyMC"; + repo = "PolyMC"; + rev = "${version}"; + sha256 = "sha256-8aya0KfV9F+i2qBpweWcR9hwyTSQkqn2wHdtkCEeNvk="; + fetchSubmodules = true; + }; + nativeBuildInputs = [ cmake file makeWrapper ]; + buildInputs = [ qtbase jdk8 zlib ]; + + patches = [ ./0001-pick-latest-java-first.patch ]; + + postPatch = '' + # hardcode jdk paths + substituteInPlace launcher/java/JavaUtils.cpp \ + --replace 'scanJavaDir("/usr/lib/jvm")' 'javas.append("${jdk}/lib/openjdk/bin/java")' \ + --replace 'scanJavaDir("/usr/lib32/jvm")' 'javas.append("${jdk8}/lib/openjdk/bin/java")' + ''; + + cmakeFlags = [ "-DLauncher_LAYOUT=lin-system" ]; + + postInstall = '' + # xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128 + wrapProgram $out/bin/polymc \ + --set GAME_LIBRARY_PATH /run/opengl-driver/lib:${libpath} \ + --prefix PATH : ${lib.makeBinPath [ xorg.xrandr ]} + ''; + + meta = with lib; { + homepage = "https://github.com/PolyMC/PolyMC"; + 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 = platforms.linux; + license = licenses.gpl3; + maintainers = with maintainers; [ cidkid ]; + }; +} \ No newline at end of file