nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 name-prefix ? "temurin",
3 brand-name ? "Eclipse Temurin",
4 sourcePerArch,
5 knownVulnerabilities ? [ ],
6}:
7
8{
9 swingSupport ? true, # not used for now
10 lib,
11 stdenv,
12 fetchurl,
13 setJavaClassPath,
14}:
15
16let
17 cpuName = stdenv.hostPlatform.parsed.cpu.name;
18 validCpuTypes = builtins.attrNames lib.systems.parse.cpuTypes;
19 providedCpuTypes = builtins.filter (arch: builtins.elem arch validCpuTypes) (
20 builtins.attrNames sourcePerArch
21 );
22 result = stdenv.mkDerivation (finalAttrs: {
23 pname =
24 if sourcePerArch.packageType == "jdk" then
25 "${name-prefix}-bin"
26 else
27 "${name-prefix}-${sourcePerArch.packageType}-bin";
28 version = sourcePerArch.${cpuName}.version or (throw "unsupported CPU ${cpuName}");
29
30 src = fetchurl {
31 inherit (sourcePerArch.${cpuName} or (throw "unsupported system ${stdenv.hostPlatform.system}"))
32 url
33 sha256
34 ;
35 };
36
37 # See: https://github.com/NixOS/patchelf/issues/10
38 dontStrip = 1;
39
40 installPhase = ''
41 cd ..
42
43 mkdir -p $out/Library/Java/JavaVirtualMachines
44
45 bundle=$out/Library/Java/JavaVirtualMachines/${name-prefix}-${lib.versions.major finalAttrs.version}.jdk
46 mv $sourceRoot $bundle
47
48 # jni.h expects jni_md.h to be in the header search path.
49 ln -s $bundle/Contents/Home/include/darwin/*_md.h $bundle/Contents/Home/include/
50
51 # Remove some broken manpages.
52 # Only for 11 and earlier.
53 [ -e "$bundle/Contents/Home/man/ja" ] && rm -r $bundle/Contents/Home/man/ja
54
55 ln -s $bundle/Contents/Home/* $out/
56
57 # Propagate the setJavaClassPath setup hook from the JDK so that
58 # any package that depends on the JDK has $CLASSPATH set up
59 # properly.
60 mkdir -p $out/nix-support
61 printWords ${setJavaClassPath} > $out/nix-support/propagated-build-inputs
62
63 # Set JAVA_HOME automatically.
64 cat <<EOF >> $out/nix-support/setup-hook
65 if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
66 EOF
67 '';
68
69 # FIXME: use multiple outputs or return actual JRE package
70 passthru = {
71 jre = finalAttrs.finalPackage;
72 home = finalAttrs.finalPackage;
73 bundle = "${finalAttrs.finalPackage}/Library/Java/JavaVirtualMachines/${name-prefix}-${lib.versions.major finalAttrs.version}.jdk";
74 };
75
76 meta = {
77 license = with lib.licenses; [
78 gpl2
79 classpathException20
80 ];
81 sourceProvenance = with lib.sourceTypes; [
82 binaryNativeCode
83 binaryBytecode
84 ];
85 description = "${brand-name}, prebuilt OpenJDK binary";
86 platforms = map (arch: arch + "-darwin") providedCpuTypes; # some inherit jre.meta.platforms
87 maintainers = with lib.maintainers; [ taku0 ];
88 teams = [ lib.teams.java ];
89 inherit knownVulnerabilities;
90 mainProgram = "java";
91 };
92 });
93in
94result