Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at fix-function-merge 190 lines 4.8 kB view raw
1{ productVersion 2, patchVersion 3, sha256 4, jceName 5, sha256JCE 6}: 7 8{ swingSupport ? true 9, lib, stdenv 10, requireFile 11, makeWrapper 12, unzip 13, file 14, xorg ? null 15, installjdk ? true 16, pluginSupport ? true 17, installjce ? false 18, config 19, glib 20, libxml2 21, ffmpeg 22, libxslt 23, libGL 24, freetype 25, fontconfig 26, gtk2 27, pango 28, cairo 29, alsa-lib 30, atk 31, gdk-pixbuf 32, setJavaClassPath 33}: 34 35assert swingSupport -> xorg != null; 36 37let 38 39 /** 40 * The JRE libraries are in directories that depend on the CPU. 41 */ 42 architecture = { 43 i686-linux = "i386"; 44 x86_64-linux = "amd64"; 45 armv7l-linux = "arm"; 46 aarch64-linux = "aarch64"; 47 }.${stdenv.hostPlatform.system} or (throw "unsupported system ${stdenv.hostPlatform.system}"); 48 49 jce = 50 if installjce then 51 requireFile { 52 name = jceName; 53 url = "http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html"; 54 sha256 = sha256JCE; 55 } 56 else 57 ""; 58 59 rSubPaths = [ 60 "lib/${architecture}/jli" 61 "lib/${architecture}/server" 62 "lib/${architecture}/xawt" 63 "lib/${architecture}" 64 ]; 65 66in 67 68let result = stdenv.mkDerivation rec { 69 pname = if installjdk then "oraclejdk" else "oraclejre" + lib.optionalString pluginSupport "-with-plugin"; 70 version = "${productVersion}u${patchVersion}"; 71 72 src = 73 let 74 platformName = { 75 i686-linux = "linux-i586"; 76 x86_64-linux = "linux-x64"; 77 armv7l-linux = "linux-arm32-vfp-hflt"; 78 aarch64-linux = "linux-aarch64"; 79 }.${stdenv.hostPlatform.system} or (throw "unsupported system ${stdenv.hostPlatform.system}"); 80 in requireFile { 81 name = "jdk-${productVersion}u${patchVersion}-${platformName}.tar.gz"; 82 url = "http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html"; 83 sha256 = sha256.${stdenv.hostPlatform.system} or (throw "unsupported system ${stdenv.hostPlatform.system}"); 84 }; 85 86 nativeBuildInputs = [ file makeWrapper ] 87 ++ lib.optional installjce unzip; 88 89 # See: https://github.com/NixOS/patchelf/issues/10 90 dontStrip = 1; 91 92 installPhase = '' 93 cd .. 94 95 if test -z "$installjdk"; then 96 mv $sourceRoot/jre $out 97 else 98 mv $sourceRoot $out 99 fi 100 101 shopt -s extglob 102 for file in $out/!(*src.zip) 103 do 104 if test -f $file ; then 105 rm $file 106 fi 107 done 108 109 if test -n "$installjdk"; then 110 for file in $out/jre/* 111 do 112 if test -f $file ; then 113 rm $file 114 fi 115 done 116 fi 117 118 if test -z "$installjdk"; then 119 jrePath=$out 120 else 121 jrePath=$out/jre 122 fi 123 124 if test -n "${jce}"; then 125 unzip ${jce} 126 cp -v UnlimitedJCEPolicy*/*.jar $jrePath/lib/security 127 fi 128 129 if test -z "$pluginSupport"; then 130 rm -f $out/bin/javaws 131 if test -n "$installjdk"; then 132 rm -f $out/jre/bin/javaws 133 fi 134 fi 135 136 mkdir $jrePath/lib/${architecture}/plugins 137 ln -s $jrePath/lib/${architecture}/libnpjp2.so $jrePath/lib/${architecture}/plugins 138 139 mkdir -p $out/nix-support 140 printWords ${setJavaClassPath} > $out/nix-support/propagated-build-inputs 141 142 # Set JAVA_HOME automatically. 143 cat <<EOF >> $out/nix-support/setup-hook 144 if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi 145 EOF 146 ''; 147 148 postFixup = '' 149 rpath+="''${rpath:+:}${lib.concatStringsSep ":" (map (a: "$jrePath/${a}") rSubPaths)}" 150 151 # set all the dynamic linkers 152 find $out -type f -perm -0100 \ 153 -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ 154 --set-rpath "$rpath" {} \; 155 156 find $out -name "*.so" -exec patchelf --set-rpath "$rpath" {} \; 157 158 # Oracle Java Mission Control needs to know where libgtk-x11 and related is 159 if test -n "$installjdk" -a -x $out/bin/jmc; then 160 wrapProgram "$out/bin/jmc" \ 161 --suffix-each LD_LIBRARY_PATH ':' "$rpath" 162 fi 163 ''; 164 165 inherit installjdk pluginSupport; 166 167 /** 168 * libXt is only needed on amd64 169 */ 170 libraries = 171 [stdenv.cc.libc glib libxml2 ffmpeg libxslt libGL xorg.libXxf86vm alsa-lib fontconfig freetype pango gtk2 cairo gdk-pixbuf atk] ++ 172 lib.optionals swingSupport [xorg.libX11 xorg.libXext xorg.libXtst xorg.libXi xorg.libXp xorg.libXt xorg.libXrender stdenv.cc.cc]; 173 174 rpath = lib.strings.makeLibraryPath libraries; 175 176 passthru.mozillaPlugin = if installjdk then "/jre/lib/${architecture}/plugins" else "/lib/${architecture}/plugins"; 177 178 passthru.jre = result; # FIXME: use multiple outputs or return actual JRE package 179 180 passthru.home = result; 181 182 passthru.architecture = architecture; 183 184 meta = with lib; { 185 license = licenses.unfree; 186 platforms = [ "i686-linux" "x86_64-linux" "armv7l-linux" "aarch64-linux" ]; # some inherit jre.meta.platforms 187 mainProgram = "java"; 188 }; 189 190}; in result