Advertisement
Guest User

openjdk.nix

a guest
Jun 19th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. { stdenv, lib, fetchurl, bash, cpio, autoconf, pkgconfig, file, which, unzip, zip, cups, freetype
  2. , alsaLib, bootjdk, perl, liberation_ttf, fontconfig, zlib, lndir
  3. , libX11, libICE, libXrender, libXext, libXt, libXtst, libXi, libXinerama, libXcursor, libXrandr
  4. , libjpeg, giflib
  5. , setJavaClassPath
  6. , minimal ? false
  7. , enableGnome2 ? true, gtk3, gnome_vfs, glib, GConf
  8. , enablejfx ? false, openjfx
  9. }:
  10.  
  11. let
  12.  
  13. /**
  14. * The JDK libraries are in directories that depend on the CPU.
  15. */
  16. architecture =
  17. if stdenv.hostPlatform.system == "i686-linux" then
  18. "i386"
  19. else "amd64";
  20.  
  21. major = "11";
  22. update = ".0.3";
  23. build = "ga";
  24. repover = "jdk-${major}${update}-${build}";
  25.  
  26. openjdk = stdenv.mkDerivation {
  27. name = "openjdk-${major}${update}-${build}";
  28.  
  29. src = fetchurl {
  30. url = "http://hg.openjdk.java.net/jdk-updates/jdk${major}u/archive/${repover}.tar.gz";
  31. sha256 = "1v6pam38iidlhz46046h17hf5kki6n3kl302awjcyxzk7bmkvb8x";
  32. };
  33.  
  34. nativeBuildInputs = [ pkgconfig ];
  35. buildInputs = [
  36. autoconf cpio file which unzip zip perl bootjdk zlib cups freetype alsaLib
  37. libjpeg giflib libX11 libICE libXext libXrender libXtst libXt libXtst
  38. libXi libXinerama libXcursor libXrandr lndir fontconfig
  39. ] ++ lib.optionals (!minimal && enableGnome2) [
  40. gtk3 gnome_vfs GConf glib
  41. ];
  42.  
  43. patches = [
  44. ./fix-java-home-jdk10.patch
  45. ./read-truststore-from-env-jdk10.patch
  46. ./currency-date-range-jdk10.patch
  47. ] ++ lib.optionals (!minimal && enableGnome2) [
  48. ./swing-use-gtk-jdk10.patch
  49. ];
  50.  
  51. preConfigure = ''
  52. chmod +x configure
  53. substituteInPlace configure --replace /bin/bash "${bash}/bin/bash"
  54.  
  55. configureFlagsArray=(
  56. "--with-boot-jdk=${bootjdk.home}"
  57. "--with-update-version=${major}${update}"
  58. "--with-build-number=${build}"
  59. "--with-milestone=fcs"
  60. "--enable-unlimited-crypto"
  61. "--disable-debug-symbols"
  62. "--with-zlib=system"
  63. "--with-giflib=system"
  64. "--with-stdc++lib=dynamic"
  65.  
  66. # glibc 2.24 deprecated readdir_r so we need this
  67. # See https://www.mail-archive.com/openembedded-devel@lists.openembedded.org/msg49006.html
  68. "--with-extra-cflags=-Wno-error=deprecated-declarations -Wno-error=format-contains-nul -Wno-error=unused-result"
  69. ''
  70. + lib.optionalString (architecture == "amd64") " \"--with-jvm-features=zgc\""
  71. + lib.optionalString minimal " \"--enable-headless-only\""
  72. + lib.optionalString openjfx " \"--with-import-modules=${openjfx}/lib\""
  73. + ");"
  74. # https://bugzilla.redhat.com/show_bug.cgi?id=1306558
  75. # https://github.com/JetBrains/jdk8u/commit/eaa5e0711a43d64874111254d74893fa299d5716
  76. + stdenv.lib.optionalString stdenv.cc.isGNU ''
  77. NIX_CFLAGS_COMPILE+=" -fno-lifetime-dse -fno-delete-null-pointer-checks -std=gnu++98 -Wno-error"
  78. '';
  79.  
  80. NIX_LDFLAGS= lib.optionals (!minimal) [
  81. "-lfontconfig" "-lcups" "-lXinerama" "-lXrandr" "-lmagic"
  82. ] ++ lib.optionals (!minimal && enableGnome2) [
  83. "-lgtk-3" "-lgio-2.0" "-lgnomevfs-2" "-lgconf-2"
  84. ];
  85.  
  86. buildFlags = [ "all" ];
  87.  
  88. installPhase = ''
  89. mkdir -p $out/lib/openjdk $out/share
  90.  
  91. cp -av build/*/images/jdk/* $out/lib/openjdk
  92.  
  93. # Remove some broken manpages.
  94. rm -rf $out/lib/openjdk/man/ja*
  95.  
  96. # Mirror some stuff in top-level.
  97. mkdir $out/include $out/share/man
  98. ln -s $out/lib/openjdk/include/* $out/include/
  99. ln -s $out/lib/openjdk/man/* $out/share/man/
  100.  
  101. # jni.h expects jni_md.h to be in the header search path.
  102. ln -s $out/include/linux/*_md.h $out/include/
  103.  
  104. # Remove crap from the installation.
  105. rm -rf $out/lib/openjdk/demo
  106. ${lib.optionalString minimal ''
  107. rm $out/lib/openjdk/lib/{libjsound,libfontmanager}.so
  108. ''}
  109.  
  110. ln -s $out/lib/openjdk/bin $out/bin
  111. '';
  112.  
  113. preFixup = ''
  114. # Propagate the setJavaClassPath setup hook so that any package
  115. # that depends on the JDK has $CLASSPATH set up properly.
  116. mkdir -p $out/nix-support
  117. #TODO or printWords? cf https://github.com/NixOS/nixpkgs/pull/27427#issuecomment-317293040
  118. echo -n "${setJavaClassPath}" > $out/nix-support/propagated-build-inputs
  119.  
  120. # Set JAVA_HOME automatically.
  121. mkdir -p $out/nix-support
  122. cat <<EOF > $out/nix-support/setup-hook
  123. if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out/lib/openjdk; fi
  124. EOF
  125. '';
  126.  
  127. postFixup = ''
  128. # Build the set of output library directories to rpath against
  129. LIBDIRS=""
  130. for output in $outputs; do
  131. LIBDIRS="$(find $(eval echo \$$output) -name \*.so\* -exec dirname {} \+ | sort | uniq | tr '\n' ':'):$LIBDIRS"
  132. done
  133.  
  134. # Add the local library paths to remove dependencies on the bootstrap
  135. for output in $outputs; do
  136. OUTPUTDIR=$(eval echo \$$output)
  137. BINLIBS=$(find $OUTPUTDIR/bin/ -type f; find $OUTPUTDIR -name \*.so\*)
  138. echo "$BINLIBS" | while read i; do
  139. patchelf --set-rpath "$LIBDIRS:$(patchelf --print-rpath "$i")" "$i" || true
  140. patchelf --shrink-rpath "$i" || true
  141. done
  142. done
  143.  
  144. # Test to make sure that we don't depend on the bootstrap
  145. for output in $outputs; do
  146. if grep -q -r '${bootjdk}' $(eval echo \$$output); then
  147. echo "Extraneous references to ${bootjdk} detected"
  148. exit 1
  149. fi
  150. done
  151. '';
  152.  
  153. meta = with stdenv.lib; {
  154. homepage = http://openjdk.java.net/;
  155. license = licenses.gpl2;
  156. description = "The open-source Java Development Kit";
  157. maintainers = with maintainers; [ edwtjo ];
  158. platforms = ["i686-linux" "x86_64-linux"];
  159. };
  160.  
  161. passthru = {
  162. inherit architecture;
  163. home = "${openjdk}/lib/openjdk";
  164. };
  165. };
  166. in openjdk
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement