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