summaryrefslogtreecommitdiff
path: root/pkgs/development/compilers/temurin-bin/jdk-darwin-base.nix
blob: 58803637f81c7b3be6711f978874c1f0218ecdc5 (about) (plain)
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
{
  name-prefix ? "temurin",
  brand-name ? "Eclipse Temurin",
  sourcePerArch,
  knownVulnerabilities ? [ ],
}:

{
  swingSupport ? true, # not used for now
  lib,
  stdenv,
  fetchurl,
  setJavaClassPath,
}:

let
  cpuName = stdenv.hostPlatform.parsed.cpu.name;
  validCpuTypes = builtins.attrNames lib.systems.parse.cpuTypes;
  providedCpuTypes = builtins.filter (arch: builtins.elem arch validCpuTypes) (
    builtins.attrNames sourcePerArch
  );
  result = stdenv.mkDerivation (finalAttrs: {
    pname =
      if sourcePerArch.packageType == "jdk" then
        "${name-prefix}-bin"
      else
        "${name-prefix}-${sourcePerArch.packageType}-bin";
    version = sourcePerArch.${cpuName}.version or (throw "unsupported CPU ${cpuName}");

    src = fetchurl {
      inherit (sourcePerArch.${cpuName} or (throw "unsupported system ${stdenv.hostPlatform.system}"))
        url
        sha256
        ;
    };

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

    installPhase = ''
      cd ..

      mkdir -p $out/Library/Java/JavaVirtualMachines

      bundle=$out/Library/Java/JavaVirtualMachines/${name-prefix}-${lib.versions.major finalAttrs.version}.jdk
      mv $sourceRoot $bundle

      # jni.h expects jni_md.h to be in the header search path.
      ln -s $bundle/Contents/Home/include/darwin/*_md.h $bundle/Contents/Home/include/

      # Remove some broken manpages.
      # Only for 11 and earlier.
      [ -e "$bundle/Contents/Home/man/ja" ] && rm -r $bundle/Contents/Home/man/ja

      ln -s $bundle/Contents/Home/* $out/

      # Propagate the setJavaClassPath setup hook from the JDK so that
      # any package that depends on the JDK has $CLASSPATH set up
      # properly.
      mkdir -p $out/nix-support
      printWords ${setJavaClassPath} > $out/nix-support/propagated-build-inputs

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

    # FIXME: use multiple outputs or return actual JRE package
    passthru = {
      jre = finalAttrs.finalPackage;
      home = finalAttrs.finalPackage;
      bundle = "${finalAttrs.finalPackage}/Library/Java/JavaVirtualMachines/${name-prefix}-${lib.versions.major finalAttrs.version}.jdk";
    };

    meta = with lib; {
      license = licenses.gpl2Classpath;
      sourceProvenance = with sourceTypes; [
        binaryNativeCode
        binaryBytecode
      ];
      description = "${brand-name}, prebuilt OpenJDK binary";
      platforms = builtins.map (arch: arch + "-darwin") providedCpuTypes; # some inherit jre.meta.platforms
      maintainers = with maintainers; [ taku0 ] ++ lib.teams.java.members;
      inherit knownVulnerabilities;
      mainProgram = "java";
    };
  });
in
result