lol
1{ stdenv, fetchurl, cpio, file, which, unzip, zip, xorg, cups, freetype
2, alsaLib, bootjdk, cacert, perl, liberation_ttf, fontconfig, zlib
3, setJavaClassPath
4, minimal ? false
5}:
6
7let
8
9 /**
10 * The JRE libraries are in directories that depend on the CPU.
11 */
12 architecture =
13 if stdenv.system == "i686-linux" then
14 "i386"
15 else if stdenv.system == "x86_64-linux" then
16 "amd64"
17 else
18 throw "openjdk requires i686-linux or x86_64 linux";
19
20 update = "60";
21 build = "24";
22 baseurl = "http://hg.openjdk.java.net/jdk8u/jdk8u";
23 repover = "jdk8u${update}-b${build}";
24 paxflags = if stdenv.isi686 then "msp" else "m";
25 jdk8 = fetchurl {
26 url = "${baseurl}/archive/${repover}.tar.gz";
27 sha256 = "1gxfyz5kdl3xgfmn6gr65hj66zh5p67y1g0hxdbps1h8gcc6iqwp";
28 };
29 langtools = fetchurl {
30 url = "${baseurl}/langtools/archive/${repover}.tar.gz";
31 sha256 = "0a8kmfcnw92hvhivmpa9g22k1lvcr64zjw7x1gjj1j6zx7r579ck";
32 };
33 hotspot = fetchurl {
34 url = "${baseurl}/hotspot/archive/${repover}.tar.gz";
35 sha256 = "0k68wqwg5fz8i2za9dg2zfx4db5zcbls31vk2abrqrwp31ik0y4y";
36 };
37 corba = fetchurl {
38 url = "${baseurl}/corba/archive/${repover}.tar.gz";
39 sha256 = "0rc8m5jrwjzrbxnzbhxjm265z23ky6v11g8sgcb6flr0l636fwvn";
40 };
41 jdk = fetchurl {
42 url = "${baseurl}/jdk/archive/${repover}.tar.gz";
43 sha256 = "11c90zz728p30zc6zas9ip67n9sd09i0v6afxs608k9s451057wr";
44 };
45 jaxws = fetchurl {
46 url = "${baseurl}/jaxws/archive/${repover}.tar.gz";
47 sha256 = "15pzczqwrr47qv51bsisjylilhljban8938n1436hsjd5k1dhhwn";
48 };
49 jaxp = fetchurl {
50 url = "${baseurl}/jaxp/archive/${repover}.tar.gz";
51 sha256 = "0gcc7pb07yl76drcynpz5gjjv3y6s1c0k4kfp9fayha5f624k1fb";
52 };
53 nashorn = fetchurl {
54 url = "${baseurl}/nashorn/archive/${repover}.tar.gz";
55 sha256 = "00g849wwqxljqpml6r7rv3pscj0ma0jaamyvxsxlfxbqvwid93ai";
56 };
57 openjdk8 = stdenv.mkDerivation {
58 name = "openjdk-8u${update}b${build}";
59
60 srcs = [ jdk8 langtools hotspot corba jdk jaxws jaxp nashorn ];
61 sourceRoot = ".";
62
63 outputs = [ "out" "jre" ];
64
65 buildInputs = [
66 cpio file which unzip zip
67 xorg.libX11 xorg.libXt xorg.libXext xorg.libXrender xorg.libXtst
68 xorg.libXi xorg.libXinerama xorg.libXcursor xorg.lndir
69 cups freetype alsaLib perl liberation_ttf fontconfig bootjdk zlib
70 ];
71
72 prePatch = ''
73 ls | grep jdk | grep -v '^jdk8u' | awk -F- '{print $1}' | while read p; do
74 mv $p-* $(ls | grep '^jdk8u')/$p
75 done
76 cd $(ls | grep '^jdk8u')
77 '';
78
79 patches = [
80 ./fix-java-home-jdk8.patch
81 ./read-truststore-from-env-jdk8.patch
82 ./currency-date-range-jdk8.patch
83 ];
84
85 preConfigure = ''
86 chmod +x configure
87 substituteInPlace configure --replace /bin/bash "$shell"
88 substituteInPlace hotspot/make/linux/adlc_updater --replace /bin/sh "$shell"
89 '';
90
91 configureFlags = [
92 "--with-freetype=${freetype}"
93 "--with-boot-jdk=${bootjdk.home}"
94 "--with-update-version=${update}"
95 "--with-build-number=${build}"
96 "--with-milestone=fcs"
97 "--enable-unlimited-crypto"
98 "--disable-debug-symbols"
99 "--disable-freetype-bundling"
100 ] ++ (if minimal then [
101 "--disable-headful"
102 "--with-zlib=bundled"
103 "--with-giflib=bundled"
104 ] else [
105 "--with-zlib=system"
106 ]);
107
108 NIX_LDFLAGS= if minimal then null else "-lfontconfig";
109
110 buildFlags = "all";
111
112 installPhase = ''
113 mkdir -p $out/lib/openjdk $out/share $jre/lib/openjdk
114
115 cp -av build/*/images/j2sdk-image/* $out/lib/openjdk
116
117 # Move some stuff to top-level.
118 mv $out/lib/openjdk/include $out/include
119 mv $out/lib/openjdk/man $out/share/man
120
121 # jni.h expects jni_md.h to be in the header search path.
122 ln -s $out/include/linux/*_md.h $out/include/
123
124 # Remove some broken manpages.
125 rm -rf $out/share/man/ja*
126
127 # Remove crap from the installation.
128 rm -rf $out/lib/openjdk/demo $out/lib/openjdk/sample
129
130 # Move the JRE to a separate output and setup fallback fonts
131 mv $out/lib/openjdk/jre $jre/lib/openjdk/
132 mkdir $out/lib/openjdk/jre
133 mkdir -p $jre/lib/openjdk/jre/lib/fonts/fallback
134 lndir ${liberation_ttf}/share/fonts/truetype $jre/lib/openjdk/jre/lib/fonts/fallback
135 lndir $jre/lib/openjdk/jre $out/lib/openjdk/jre
136
137 rm -rf $out/lib/openjdk/jre/bina
138 ln -s $out/lib/openjdk/bin $out/lib/openjdk/jre/bin
139
140 # Set PaX markings
141 exes=$(file $out/lib/openjdk/bin/* $jre/lib/openjdk/jre/bin/* 2> /dev/null | grep -E 'ELF.*(executable|shared object)' | sed -e 's/: .*$//')
142 echo "to mark: *$exes*"
143 for file in $exes; do
144 echo "marking *$file*"
145 paxmark ${paxflags} "$file"
146 done
147
148 # Remove duplicate binaries.
149 for i in $(cd $out/lib/openjdk/bin && echo *); do
150 if [ "$i" = java ]; then continue; fi
151 if cmp -s $out/lib/openjdk/bin/$i $jre/lib/openjdk/jre/bin/$i; then
152 ln -sfn $jre/lib/openjdk/jre/bin/$i $out/lib/openjdk/bin/$i
153 fi
154 done
155
156 # Generate certificates.
157 pushd $jre/lib/openjdk/jre/lib/security
158 rm cacerts
159 perl ${./generate-cacerts.pl} $jre/lib/openjdk/jre/bin/keytool ${cacert}/etc/ssl/certs/ca-bundle.crt
160 popd
161
162 ln -s $out/lib/openjdk/bin $out/bin
163 ln -s $jre/lib/openjdk/jre/bin $jre/bin
164 '';
165
166 # FIXME: this is unnecessary once the multiple-outputs branch is merged.
167 preFixup = ''
168 prefix=$jre stripDirs "$stripDebugList" "''${stripDebugFlags:--S}"
169 patchELF $jre
170 propagatedNativeBuildInputs+=" $jre"
171
172 # Propagate the setJavaClassPath setup hook from the JRE so that
173 # any package that depends on the JRE has $CLASSPATH set up
174 # properly.
175 mkdir -p $jre/nix-support
176 echo -n "${setJavaClassPath}" > $jre/nix-support/propagated-native-build-inputs
177
178 # Set JAVA_HOME automatically.
179 mkdir -p $out/nix-support
180 cat <<EOF > $out/nix-support/setup-hook
181 if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out/lib/openjdk; fi
182 EOF
183 '';
184
185 postFixup = ''
186 # Build the set of output library directories to rpath against
187 LIBDIRS=""
188 for output in $outputs; do
189 LIBDIRS="$(find $(eval echo \$$output) -name \*.so\* -exec dirname {} \; | sort | uniq | tr '\n' ':'):$LIBDIRS"
190 done
191
192 # Add the local library paths to remove dependencies on the bootstrap
193 for output in $outputs; do
194 OUTPUTDIR="$(eval echo \$$output)"
195 BINLIBS="$(find $OUTPUTDIR/bin/ -type f; find $OUTPUTDIR -name \*.so\*)"
196 echo "$BINLIBS" | while read i; do
197 patchelf --set-rpath "$LIBDIRS:$(patchelf --print-rpath "$i")" "$i" || true
198 patchelf --shrink-rpath "$i" || true
199 done
200 done
201
202 # Test to make sure that we don't depend on the bootstrap
203 for output in $outputs; do
204 if grep -q -r '${bootjdk}' $(eval echo \$$output); then
205 echo "Extraneous references to ${bootjdk} detected"
206 exit 1
207 fi
208 done
209 '';
210
211 meta = with stdenv.lib; {
212 homepage = http://openjdk.java.net/;
213 license = licenses.gpl2;
214 description = "The open-source Java Development Kit";
215 maintainers = with maintainers; [ edwtjo ];
216 platforms = platforms.linux;
217 };
218
219 passthru = {
220 inherit architecture;
221 home = "${openjdk8}/lib/openjdk";
222 };
223 };
224in openjdk8