nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv, lib, fetchurl, bash, cpio, pkgconfig, file, which, unzip, zip, cups, freetype
2, alsaLib, bootjdk, cacert, perl, liberation_ttf, fontconfig, zlib, lndir
3, libX11, libICE, libXrender, libXext, libXt, libXtst, libXi, libXinerama, libXcursor
4, libjpeg, giflib
5, setJavaClassPath
6, minimal ? false
7, enableInfinality ? true # font rendering patch
8, enableGnome2 ? true, gtk2, gnome_vfs, glib, GConf
9}:
10
11let
12
13 /**
14 * The JRE libraries are in directories that depend on the CPU.
15 */
16 architecture =
17 if stdenv.system == "i686-linux" then
18 "i386"
19 else if stdenv.system == "x86_64-linux" then
20 "amd64"
21 else
22 throw "openjdk requires i686-linux or x86_64 linux";
23
24 update = "144";
25 build = "01";
26 baseurl = "http://hg.openjdk.java.net/jdk8u/jdk8u";
27 repover = "jdk8u${update}-b${build}";
28 paxflags = if stdenv.isi686 then "msp" else "m";
29 jdk8 = fetchurl {
30 url = "${baseurl}/archive/${repover}.tar.gz";
31 sha256 = "08b7ia2ifvcl8xnpflf019ak3xcbdjnxcy1mhfp3nbfsbk2sia45";
32 };
33 langtools = fetchurl {
34 url = "${baseurl}/langtools/archive/${repover}.tar.gz";
35 sha256 = "0g7q6ljvn79psrcak3l4imd27w047ngavn9jcn3xwivg5wppsfks";
36 };
37 hotspot = fetchurl {
38 url = "${baseurl}/hotspot/archive/${repover}.tar.gz";
39 sha256 = "1hbbzf0m2a78dm8pyvc11jwfpj7q67pvjrp3hf0cnc38k9mzrn8q";
40 };
41 corba = fetchurl {
42 url = "${baseurl}/corba/archive/${repover}.tar.gz";
43 sha256 = "1znc0prsb814ggm6qjgbsykm864mwypnxgi9w9f9riq8gs0578gh";
44 };
45 jdk = fetchurl {
46 url = "${baseurl}/jdk/archive/${repover}.tar.gz";
47 sha256 = "0gx5md1v1jmqhdwcc7smpf46sgp4alvb6jz3n6yjlcyfzk92yi78";
48 };
49 jaxws = fetchurl {
50 url = "${baseurl}/jaxws/archive/${repover}.tar.gz";
51 sha256 = "0ad9w7gnwlpdssw2p3kfny02mmvzc6z8i2n7qq0177ml48c88iji";
52 };
53 jaxp = fetchurl {
54 url = "${baseurl}/jaxp/archive/${repover}.tar.gz";
55 sha256 = "14yzbbishsyrzmymws6mnndqj6hvs69ivfdbjhgwi0wl23g9siym";
56 };
57 nashorn = fetchurl {
58 url = "${baseurl}/nashorn/archive/${repover}.tar.gz";
59 sha256 = "175q29n4bfmm1cyyga7x58zhh6ann9rm3wibw0scrhgy23lx052x";
60 };
61 openjdk8 = stdenv.mkDerivation {
62 name = "openjdk-8u${update}b${build}";
63
64 srcs = [ jdk8 langtools hotspot corba jdk jaxws jaxp nashorn ];
65 sourceRoot = ".";
66
67 outputs = [ "out" "jre" ];
68
69 nativeBuildInputs = [ pkgconfig ];
70 buildInputs = [
71 cpio file which unzip zip perl bootjdk zlib cups freetype alsaLib
72 libjpeg giflib libX11 libICE libXext libXrender libXtst libXt libXtst
73 libXi libXinerama libXcursor lndir fontconfig
74 ] ++ lib.optionals (!minimal && enableGnome2) [
75 gtk2 gnome_vfs GConf glib
76 ];
77
78 #move the seven other source dirs under the main jdk8u directory,
79 #with version suffixes removed, as the remainder of the build will expect
80 prePatch = ''
81 mainDir=$(find . -maxdepth 1 -name jdk8u\*);
82 find . -maxdepth 1 -name \*jdk\* -not -name jdk8u\* | awk -F- '{print $1}' | while read p; do
83 mv $p-* $mainDir/$p
84 done
85 cd $mainDir
86 '';
87
88 patches = [
89 ./fix-java-home-jdk8.patch
90 ./read-truststore-from-env-jdk8.patch
91 ./currency-date-range-jdk8.patch
92 ] ++ lib.optionals (!minimal && enableInfinality) [
93 ./004_add-fontconfig.patch
94 ./005_enable-infinality.patch
95 ] ++ lib.optionals (!minimal && enableGnome2) [
96 ./swing-use-gtk.patch
97 ];
98
99 preConfigure = ''
100 chmod +x configure
101 substituteInPlace configure --replace /bin/bash "${bash}/bin/bash"
102 substituteInPlace hotspot/make/linux/adlc_updater --replace /bin/sh "$shell"
103 substituteInPlace hotspot/make/linux/makefiles/dtrace.make --replace /usr/include/sys/sdt.h "/no-such-path"
104 ''
105 # https://bugzilla.redhat.com/show_bug.cgi?id=1306558
106 # https://github.com/JetBrains/jdk8u/commit/eaa5e0711a43d64874111254d74893fa299d5716
107 + stdenv.lib.optionalString stdenv.cc.isGNU ''
108 NIX_CFLAGS_COMPILE+=" -fno-lifetime-dse -fno-delete-null-pointer-checks -std=gnu++98 -Wno-error"
109 '';
110
111 configureFlags = [
112 "--with-boot-jdk=${bootjdk.home}"
113 "--with-update-version=${update}"
114 "--with-build-number=${build}"
115 "--with-milestone=fcs"
116 "--enable-unlimited-crypto"
117 "--disable-debug-symbols"
118 "--disable-freetype-bundling"
119 "--with-zlib=system"
120 "--with-giflib=system"
121 "--with-stdc++lib=dynamic"
122
123 # glibc 2.24 deprecated readdir_r so we need this
124 # See https://www.mail-archive.com/openembedded-devel@lists.openembedded.org/msg49006.html
125 "--with-extra-cflags=\"-Wno-error=deprecated-declarations\""
126 ] ++ lib.optional minimal "--disable-headful";
127
128 NIX_LDFLAGS= lib.optionals (!minimal) [
129 "-lfontconfig" "-lcups" "-lXinerama" "-lXrandr" "-lmagic"
130 ] ++ lib.optionals (!minimal && enableGnome2) [
131 "-lgtk-x11-2.0" "-lgio-2.0" "-lgnomevfs-2" "-lgconf-2"
132 ];
133
134 buildFlags = [ "all" ];
135
136 installPhase = ''
137 mkdir -p $out/lib/openjdk $out/share $jre/lib/openjdk
138
139 cp -av build/*/images/j2sdk-image/* $out/lib/openjdk
140
141 # Remove some broken manpages.
142 rm -rf $out/lib/openjdk/man/ja*
143
144 # Mirror some stuff in top-level.
145 mkdir $out/include $out/share/man
146 ln -s $out/lib/openjdk/include/* $out/include/
147 ln -s $out/lib/openjdk/man/* $out/share/man/
148
149 # jni.h expects jni_md.h to be in the header search path.
150 ln -s $out/include/linux/*_md.h $out/include/
151
152 # Remove crap from the installation.
153 rm -rf $out/lib/openjdk/demo $out/lib/openjdk/sample
154 ${lib.optionalString minimal ''
155 rm $out/lib/openjdk/jre/lib/${architecture}/{libjsound,libjsoundalsa,libsplashscreen,libawt*,libfontmanager}.so
156 rm $out/lib/openjdk/jre/bin/policytool
157 rm $out/lib/openjdk/bin/{policytool,appletviewer}
158 ''}
159
160 # Move the JRE to a separate output and setup fallback fonts
161 mv $out/lib/openjdk/jre $jre/lib/openjdk/
162 mkdir $out/lib/openjdk/jre
163 ${lib.optionalString (!minimal) ''
164 mkdir -p $jre/lib/openjdk/jre/lib/fonts/fallback
165 lndir ${liberation_ttf}/share/fonts/truetype $jre/lib/openjdk/jre/lib/fonts/fallback
166 ''}
167 lndir $jre/lib/openjdk/jre $out/lib/openjdk/jre
168
169 rm -rf $out/lib/openjdk/jre/bina
170 ln -s $out/lib/openjdk/bin $out/lib/openjdk/jre/bin
171
172 # Make sure cmm/*.pf are not symlinks:
173 # https://youtrack.jetbrains.com/issue/IDEA-147272
174 rm -rf $out/lib/openjdk/jre/lib/cmm
175 ln -s {$jre,$out}/lib/openjdk/jre/lib/cmm
176
177 # Set PaX markings
178 exes=$(file $out/lib/openjdk/bin/* $jre/lib/openjdk/jre/bin/* 2> /dev/null | grep -E 'ELF.*(executable|shared object)' | sed -e 's/: .*$//')
179 echo "to mark: *$exes*"
180 for file in $exes; do
181 echo "marking *$file*"
182 paxmark ${paxflags} "$file"
183 done
184
185 # Remove duplicate binaries.
186 for i in $(cd $out/lib/openjdk/bin && echo *); do
187 if [ "$i" = java ]; then continue; fi
188 if cmp -s $out/lib/openjdk/bin/$i $jre/lib/openjdk/jre/bin/$i; then
189 ln -sfn $jre/lib/openjdk/jre/bin/$i $out/lib/openjdk/bin/$i
190 fi
191 done
192
193 # Generate certificates.
194 (
195 cd $jre/lib/openjdk/jre/lib/security
196 rm cacerts
197 perl ${./generate-cacerts.pl} $jre/lib/openjdk/jre/bin/keytool ${cacert}/etc/ssl/certs/ca-bundle.crt
198 )
199
200 ln -s $out/lib/openjdk/bin $out/bin
201 ln -s $jre/lib/openjdk/jre/bin $jre/bin
202 ln -s $jre/lib/openjdk/jre $out/jre
203 '';
204
205 # FIXME: this is unnecessary once the multiple-outputs branch is merged.
206 preFixup = ''
207 prefix=$jre stripDirs "$stripDebugList" "''${stripDebugFlags:--S}"
208 patchELF $jre
209 propagatedNativeBuildInputs+=" $jre"
210
211 # Propagate the setJavaClassPath setup hook from the JRE so that
212 # any package that depends on the JRE has $CLASSPATH set up
213 # properly.
214 mkdir -p $jre/nix-support
215 printWords ${setJavaClassPath} > $jre/nix-support/propagated-native-build-inputs
216
217 # Set JAVA_HOME automatically.
218 mkdir -p $out/nix-support
219 cat <<EOF > $out/nix-support/setup-hook
220 if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out/lib/openjdk; fi
221 EOF
222 '';
223
224 postFixup = ''
225 # Build the set of output library directories to rpath against
226 LIBDIRS=""
227 for output in $outputs; do
228 LIBDIRS="$(find $(eval echo \$$output) -name \*.so\* -exec dirname {} \+ | sort | uniq | tr '\n' ':'):$LIBDIRS"
229 done
230
231 # Add the local library paths to remove dependencies on the bootstrap
232 for output in $outputs; do
233 OUTPUTDIR=$(eval echo \$$output)
234 BINLIBS=$(find $OUTPUTDIR/bin/ -type f; find $OUTPUTDIR -name \*.so\*)
235 echo "$BINLIBS" | while read i; do
236 patchelf --set-rpath "$LIBDIRS:$(patchelf --print-rpath "$i")" "$i" || true
237 patchelf --shrink-rpath "$i" || true
238 done
239 done
240
241 # Test to make sure that we don't depend on the bootstrap
242 for output in $outputs; do
243 if grep -q -r '${bootjdk}' $(eval echo \$$output); then
244 echo "Extraneous references to ${bootjdk} detected"
245 exit 1
246 fi
247 done
248 '';
249
250 meta = with stdenv.lib; {
251 homepage = http://openjdk.java.net/;
252 license = licenses.gpl2;
253 description = "The open-source Java Development Kit";
254 maintainers = with maintainers; [ edwtjo nequissimus ];
255 platforms = platforms.linux;
256 };
257
258 passthru = {
259 inherit architecture;
260 home = "${openjdk8}/lib/openjdk";
261 };
262 };
263in openjdk8