Skip to content

Commit

Permalink
Build custom JRE package
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
9ary committed Feb 9, 2025
1 parent 4cfd98f commit 03ee759
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
34 changes: 34 additions & 0 deletions jre.nix
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 6 additions & 4 deletions packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -171,7 +173,7 @@ lib.makeScope newScope (

runServer = callPackage ({
writeShellApplication,
jre17_minimal,
jre,
unsup,
}:
writeShellApplication {
Expand All @@ -191,7 +193,7 @@ lib.makeScope newScope (
echo 'eula=true' > eula.txt
./forge-server/run.sh --nogui "$@"
'';
runtimeInputs = [jre17_minimal];
runtimeInputs = [jre];
}) {};
}
)

0 comments on commit 03ee759

Please sign in to comment.