1{
2 lib,
3 stdenv,
4 fetchurl,
5 setJavaClassPath,
6 testers,
7 enableJavaFX ? false,
8 dists,
9 # minimum dependencies
10 unzip,
11 autoPatchelfHook,
12 makeWrapper,
13 alsa-lib,
14 fontconfig,
15 freetype,
16 zlib,
17 xorg,
18 # runtime dependencies
19 cups,
20 # runtime dependencies for GTK+ Look and Feel
21 gtkSupport ? stdenv.hostPlatform.isLinux,
22 cairo,
23 glib,
24 gtk2,
25 gtk3,
26 # runtime dependencies for JavaFX
27 ffmpeg,
28}:
29let
30 dist =
31 dists.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
32
33 arch =
34 {
35 "aarch64" = "aarch64";
36 "x86_64" = "x64";
37 }
38 .${stdenv.hostPlatform.parsed.cpu.name}
39 or (throw "Unsupported architecture: ${stdenv.hostPlatform.parsed.cpu.name}");
40
41 platform =
42 {
43 "darwin" = "macosx";
44 "linux" = "linux";
45 }
46 .${stdenv.hostPlatform.parsed.kernel.name}
47 or (throw "Unsupported platform: ${stdenv.hostPlatform.parsed.kernel.name}");
48
49 runtimeDependencies = [
50 cups
51 ]
52 ++ lib.optionals gtkSupport [
53 cairo
54 glib
55 gtk3
56 ]
57 ++ lib.optionals (gtkSupport && lib.versionOlder dist.jdkVersion "17") [
58 gtk2
59 ]
60 ++ lib.optionals (stdenv.hostPlatform.isLinux && enableJavaFX) [
61 ffmpeg.lib
62 ];
63
64 runtimeLibraryPath = lib.makeLibraryPath runtimeDependencies;
65
66 jce-policies = fetchurl {
67 url = "https://web.archive.org/web/20211126120343/http://cdn.azul.com/zcek/bin/ZuluJCEPolicies.zip";
68 hash = "sha256-gCGii4ysQbRPFCH9IQoKCCL8r4jWLS5wo1sv9iioZ1o=";
69 };
70
71 javaPackage = if enableJavaFX then "ca-fx-jdk" else "ca-jdk";
72
73 isJdk8 = lib.versions.major dist.jdkVersion == "8";
74
75 jdk = stdenv.mkDerivation rec {
76 pname = "zulu-${javaPackage}";
77 version = dist.jdkVersion;
78
79 src = fetchurl {
80 url = "https://cdn.azul.com/zulu/bin/zulu${dist.zuluVersion}-${javaPackage}${dist.jdkVersion}-${platform}_${arch}.tar.gz";
81 inherit (dist) hash;
82 curlOpts = "-H Referer:https://www.azul.com/downloads/zulu/";
83 };
84
85 nativeBuildInputs = [
86 unzip
87 ]
88 ++ lib.optionals stdenv.hostPlatform.isLinux [
89 autoPatchelfHook
90 makeWrapper
91 ];
92
93 buildInputs =
94 lib.optionals stdenv.hostPlatform.isLinux [
95 alsa-lib # libasound.so wanted by lib/libjsound.so
96 fontconfig
97 freetype
98 stdenv.cc.cc # libstdc++.so.6
99 xorg.libX11
100 xorg.libXext
101 xorg.libXi
102 xorg.libXrender
103 xorg.libXtst
104 xorg.libXxf86vm
105 zlib
106 ]
107 ++ lib.optionals (stdenv.hostPlatform.isLinux && enableJavaFX) runtimeDependencies;
108
109 autoPatchelfIgnoreMissingDeps =
110 if (stdenv.hostPlatform.isLinux && enableJavaFX) then
111 [
112 "libavcodec*.so.*"
113 "libavformat*.so.*"
114 ]
115 else
116 null;
117
118 installPhase = ''
119 mkdir -p $out
120 mv * $out
121 ''
122 + lib.optionalString stdenv.hostPlatform.isDarwin ''
123 mkdir -p $out/Library/Java/JavaVirtualMachines
124 bundle=$out/Library/Java/JavaVirtualMachines/zulu-${lib.versions.major version}.jdk
125 mv $out/zulu-${lib.versions.major version}.jdk $bundle
126 ln -sf $bundle/Contents/Home/* $out/
127 ''
128 + ''
129
130 unzip ${jce-policies}
131 mv -f ZuluJCEPolicies/*.jar $out/${lib.optionalString isJdk8 "jre/"}lib/security/
132
133 # jni.h expects jni_md.h to be in the header search path.
134 ln -s $out/include/${stdenv.hostPlatform.parsed.kernel.name}/*_md.h $out/include/
135
136 if [ -f $out/LICENSE ]; then
137 install -D $out/LICENSE $out/share/zulu/LICENSE
138 rm $out/LICENSE
139 fi
140 '';
141
142 preFixup = ''
143 # Propagate the setJavaClassPath setup hook from the ${if isJdk8 then "JRE" else "JDK"} so that
144 # any package that depends on the ${if isJdk8 then "JRE" else "JDK"} has $CLASSPATH set up
145 # properly.
146 mkdir -p $out/nix-support
147 printWords ${setJavaClassPath} > $out/nix-support/propagated-build-inputs
148
149 # Set JAVA_HOME automatically.
150 cat <<EOF >> $out/nix-support/setup-hook
151 if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
152 EOF
153 ''
154 + lib.optionalString stdenv.hostPlatform.isLinux ''
155 # We cannot use -exec since wrapProgram is a function but not a command.
156 #
157 # jspawnhelper is executed from JVM, so it doesn't need to wrap it, and it
158 # breaks building OpenJDK (#114495).
159 for bin in $( find "$out" -executable -type f -not -name jspawnhelper ); do
160 if patchelf --print-interpreter "$bin" &> /dev/null; then
161 wrapProgram "$bin" --prefix LD_LIBRARY_PATH : "${runtimeLibraryPath}"
162 fi
163 done
164 ''
165 # FIXME: move all of the above to installPhase.
166 + lib.optionalString stdenv.hostPlatform.isLinux ''
167 find "$out" -name libfontmanager.so -exec \
168 patchelf --add-needed libfontconfig.so {} \;
169 '';
170
171 # fixupPhase is moving the man to share/man which breaks it because it's a
172 # relative symlink.
173 postFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
174 ln -nsf $bundle/Contents/Home/man $out/share/man
175 '';
176
177 passthru =
178 (lib.optionalAttrs isJdk8 {
179 jre = jdk;
180 })
181 // {
182 home = jdk;
183 tests.version = testers.testVersion {
184 package = jdk;
185 command = "java -version";
186 version = ''openjdk version \""${
187 if lib.versions.major version == "8" then "1.8" else lib.versions.major version
188 }"'';
189 };
190 }
191 // lib.optionalAttrs stdenv.hostPlatform.isDarwin {
192 bundle = "${jdk}/Library/Java/JavaVirtualMachines/zulu-${lib.versions.major version}.jdk";
193 };
194
195 meta = {
196 description = "Certified builds of OpenJDK";
197 longDescription = ''
198 Certified builds of OpenJDK that can be deployed across multiple
199 operating systems, containers, hypervisors and Cloud platforms.
200 '';
201 homepage = "https://www.azul.com/products/zulu/";
202 license = lib.licenses.gpl2Only;
203 mainProgram = "java";
204 teams = [ lib.teams.java ];
205 platforms = builtins.attrNames dists;
206 sourceProvenance = with lib.sourceTypes; [
207 binaryBytecode
208 binaryNativeCode
209 ];
210 };
211 };
212in
213jdk