at master 1.2 kB view raw
1{ 2 stdenv, 3 jdk, 4 jdkOnBuild, # must provide jlink 5 lib, 6 callPackage, 7 modules ? [ "java.base" ], 8}: 9 10stdenv.mkDerivation (finalAttrs: { 11 pname = "${jdk.pname}-minimal-jre"; 12 version = jdk.version; 13 14 nativeBuildInputs = [ jdkOnBuild ]; 15 buildInputs = [ jdk ]; 16 strictDeps = true; 17 18 dontUnpack = true; 19 20 # Strip more heavily than the default '-S', since if you're 21 # using this derivation you probably care about this. 22 stripDebugFlags = [ "--strip-unneeded" ]; 23 24 buildPhase = '' 25 runHook preBuild 26 27 jlink --module-path ${jdk}/lib/openjdk/jmods --add-modules ${lib.concatStringsSep "," modules} --output $out 28 29 runHook postBuild 30 ''; 31 32 dontInstall = true; 33 34 passthru = { 35 home = "${finalAttrs.finalPackage}"; 36 tests = { 37 jre_minimal-hello = callPackage ./tests/test_jre_minimal.nix { }; 38 jre_minimal-hello-logging = callPackage ./tests/test_jre_minimal_with_logging.nix { }; 39 }; 40 }; 41 42 meta = jdk.meta // { 43 description = "Minimal JRE for OpenJDK ${jdk.version}"; 44 longDescription = '' 45 This is a minimal JRE built from OpenJDK, containing only the specified modules. 46 It is suitable for running Java applications that do not require the full JDK. 47 ''; 48 }; 49})