From 03ee759b02f6995e135e120fabec41e9ee870be0 Mon Sep 17 00:00:00 2001 From: novenary Date: Sun, 9 Feb 2025 17:45:16 +0200 Subject: [PATCH] Build custom JRE package The default minimal JRE in nixpkgs: - doesn't work, because it doesn't include enough modules - is based on the full JDK rather than headless, bringing in unnecessary dependencies Build our own to remedy this. --- jre.nix | 34 ++++++++++++++++++++++++++++++++++ packages.nix | 10 ++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 jre.nix diff --git a/jre.nix b/jre.nix new file mode 100644 index 0000000..1f8caba --- /dev/null +++ b/jre.nix @@ -0,0 +1,34 @@ +{ + stdenv, + jdk17_headless, + lib, + callPackage, +}: let + jdk = jdk17_headless; +in + stdenv.mkDerivation { + pname = "${jdk.pname}-minimal-jre"; + version = jdk.version; + + buildInputs = [jdk]; + + dontUnpack = true; + + # Strip more heavily than the default '-S', since if you're + # using this derivation you probably care about this. + stripDebugFlags = ["--strip-unneeded"]; + + buildPhase = '' + runHook preBuild + + mkdir modpath + ln -s ${jdk}/lib/openjdk/jmods/* modpath + # jpackage includes path references to the base JDK in some native binaries + rm modpath/jdk.jpackage.jmod + jlink --module-path modpath --add-modules ALL-MODULE-PATH --compress=2 --output $out + + runHook postBuild + ''; + + dontInstall = true; + } diff --git a/packages.nix b/packages.nix index bd4b1c1..2bb1673 100644 --- a/packages.nix +++ b/packages.nix @@ -129,10 +129,12 @@ lib.makeScope newScope ( pack-hardmode = self.pack.override {difficulty = "hardmode";}; pack-expert = self.pack.override {difficulty = "expert";}; + jre = callPackage ./jre.nix {}; + forgeServer = callPackage ({ stdenvNoCC, fetchurl, - jre17_minimal, + jre, }: stdenvNoCC.mkDerivation (finalAttrs: { pname = "forge-server"; @@ -141,7 +143,7 @@ lib.makeScope newScope ( outputHashMode = "recursive"; outputHash = "sha256-kZlxL54b/PZGdrxnN3U4NrgixRKN1eqwZ4TeRKvSpYw="; - nativeBuildInputs = [jre17_minimal]; + nativeBuildInputs = [jre]; src = fetchurl { url = "https://maven.minecraftforge.net/net/minecraftforge/forge/${finalAttrs.version}/forge-${finalAttrs.version}-installer.jar"; @@ -171,7 +173,7 @@ lib.makeScope newScope ( runServer = callPackage ({ writeShellApplication, - jre17_minimal, + jre, unsup, }: writeShellApplication { @@ -191,7 +193,7 @@ lib.makeScope newScope ( echo 'eula=true' > eula.txt ./forge-server/run.sh --nogui "$@" ''; - runtimeInputs = [jre17_minimal]; + runtimeInputs = [jre]; }) {}; } )