summary refs log tree commit diff
path: root/pkgs/development/compilers/adoptopenjdk-bin/jdk-linux-base.nix
blob: cf38ca9eaebea9ed44b82b90b5cb12733e25c0bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
{ name
, url
, sha256
}:

{ swingSupport ? true
, stdenv
, fetchurl
, file
, xorg ? null
, glib
, libxml2
, ffmpeg_2
, libxslt
, libGL
, freetype
, fontconfig
, gtk2
, pango
, cairo
, alsaLib
, atk
, gdk_pixbuf
, zlib
, elfutils
}:

assert swingSupport -> xorg != null;

let
  rSubPaths = [
    "lib/jli"
    "lib/server"
    "lib/compressedrefs" # OpenJ9
    "lib/j9vm" # OpenJ9
    "lib"
  ];

  libraries = [
    stdenv.cc.libc glib libxml2 ffmpeg_2 libxslt libGL
    xorg.libXxf86vm alsaLib fontconfig freetype pango gtk2 cairo gdk_pixbuf
    atk zlib elfutils
  ] ++ (stdenv.lib.optionals swingSupport [
    xorg.libX11 xorg.libXext xorg.libXtst xorg.libXi xorg.libXp xorg.libXt
    xorg.libXrender
    stdenv.cc.cc
  ]);
in

let result = stdenv.mkDerivation rec {
  inherit name;

  src = fetchurl {
    inherit url sha256;
  };

  nativeBuildInputs = [ file ];

  # See: https://github.com/NixOS/patchelf/issues/10
  dontStrip = 1;

  installPhase = ''
    cd ..

    # Set PaX markings
    exes=$(file $sourceRoot/bin/* 2> /dev/null | grep -E 'ELF.*(executable|shared object)' | sed -e 's/: .*$//')
    for file in $exes; do
      paxmark m "$file"
      # On x86 for heap sizes over 700MB disable SEGMEXEC and PAGEEXEC as well.
      ${stdenv.lib.optionalString stdenv.isi686 ''paxmark msp "$file"''}
    done

    mv $sourceRoot $out

    rm -rf $out/demo

    # Remove some broken manpages.
    rm -rf $out/man/ja*

    # for backward compatibility
    ln -s $out $out/jre

    mkdir -p $out/nix-support

    # Set JAVA_HOME automatically.
    cat <<EOF >> $out/nix-support/setup-hook
    if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out; fi
    EOF
  '';

  postFixup = ''
    rpath+="''${rpath:+:}${stdenv.lib.concatStringsSep ":" (map (a: "$out/${a}") rSubPaths)}"

    # set all the dynamic linkers
    find $out -type f -perm -0100 \
        -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
        --set-rpath "$rpath" {} \;

    find $out -name "*.so" -exec patchelf --set-rpath "$rpath" {} \;
  '';

  rpath = stdenv.lib.strings.makeLibraryPath libraries;

  # FIXME: use multiple outputs or return actual JRE package
  passthru.jre = result;

  passthru.home = result;

  # for backward compatibility
  passthru.architecture = "";

  meta = with stdenv.lib; {
    license = licenses.gpl2Classpath;
    description = "AdoptOpenJDK, prebuilt OpenJDK binary";
    platforms = [ "x86_64-linux" ]; # some inherit jre.meta.platforms
    maintainers = with stdenv.lib.maintainers; [ taku0 ];
  };

}; in result