core/pkgs/by-name/ja/java/zulu/common.nix

154 lines
5 KiB
Nix
Raw Normal View History

2024-05-13 21:24:10 +00:00
{ lib, stdenv, fetchurl, setJavaClassPath, enableJavaFX ? false, dists
# minimum dependencies
, unzip, autoPatchelfHook, makeWrapper, alsa-lib, fontconfig, freetype, zlib
2024-05-02 00:46:19 +00:00
, xorg
2024-05-13 21:24:10 +00:00
# runtime dependencies
2024-05-02 00:46:19 +00:00
, cups
2024-05-13 21:24:10 +00:00
# runtime dependencies for GTK+ Look and Feel
, gtkSupport ? stdenv.isLinux, cairo, glib, gtk2, gtk3
# runtime dependencies for JavaFX
, ffmpeg }:
2024-05-02 00:46:19 +00:00
let
2024-05-13 21:24:10 +00:00
dist = dists.${stdenv.hostPlatform.system} or (throw
"Unsupported system: ${stdenv.hostPlatform.system}");
2024-05-02 00:46:19 +00:00
arch = {
"aarch64" = "aarch64";
"x86_64" = "x64";
2024-05-13 21:24:10 +00:00
}.${stdenv.hostPlatform.parsed.cpu.name} or (throw
"Unsupported architecture: ${stdenv.hostPlatform.parsed.cpu.name}");
2024-05-02 00:46:19 +00:00
platform = {
"darwin" = "macosx";
"linux" = "linux";
2024-05-13 21:24:10 +00:00
}.${stdenv.hostPlatform.parsed.kernel.name} or (throw
"Unsupported platform: ${stdenv.hostPlatform.parsed.kernel.name}");
runtimeDependencies = [ cups ] ++ lib.optionals gtkSupport [ cairo glib gtk3 ]
++ lib.optionals (gtkSupport && lib.versionOlder dist.jdkVersion "17")
[ gtk2 ] ++ lib.optionals (stdenv.isLinux && enableJavaFX) [ ffmpeg.lib ];
2024-05-02 00:46:19 +00:00
runtimeLibraryPath = lib.makeLibraryPath runtimeDependencies;
jce-policies = fetchurl {
2024-05-13 21:24:10 +00:00
url =
"https://web.archive.org/web/20211126120343/http://cdn.azul.com/zcek/bin/ZuluJCEPolicies.zip";
2024-05-02 00:46:19 +00:00
hash = "sha256-gCGii4ysQbRPFCH9IQoKCCL8r4jWLS5wo1sv9iioZ1o=";
};
javaPackage = if enableJavaFX then "ca-fx-jdk" else "ca-jdk";
isJdk8 = lib.versions.major dist.jdkVersion == "8";
jdk = stdenv.mkDerivation rec {
pname = "zulu-${javaPackage}";
version = dist.jdkVersion;
src = fetchurl {
2024-05-13 21:24:10 +00:00
url =
"https://cdn.azul.com/zulu/bin/zulu${dist.zuluVersion}-${javaPackage}${dist.jdkVersion}-${platform}_${arch}.tar.gz";
2024-05-02 00:46:19 +00:00
inherit (dist) hash;
curlOpts = "-H Referer:https://www.azul.com/downloads/zulu/";
};
2024-05-13 21:24:10 +00:00
nativeBuildInputs = [ unzip ]
++ lib.optionals stdenv.isLinux [ autoPatchelfHook makeWrapper ];
2024-05-02 00:46:19 +00:00
buildInputs = lib.optionals stdenv.isLinux [
alsa-lib # libasound.so wanted by lib/libjsound.so
fontconfig
freetype
stdenv.cc.cc # libstdc++.so.6
xorg.libX11
xorg.libXext
xorg.libXi
xorg.libXrender
xorg.libXtst
xorg.libXxf86vm
zlib
] ++ lib.optionals (stdenv.isLinux && enableJavaFX) runtimeDependencies;
autoPatchelfIgnoreMissingDeps = if (stdenv.isLinux && enableJavaFX) then [
"libavcodec*.so.*"
"libavformat*.so.*"
2024-05-13 21:24:10 +00:00
] else
null;
2024-05-02 00:46:19 +00:00
installPhase = ''
mkdir -p $out
mv * $out
unzip ${jce-policies}
2024-05-13 21:24:10 +00:00
mv -f ZuluJCEPolicies/*.jar $out/${
lib.optionalString isJdk8 "jre/"
}lib/security/
2024-05-02 00:46:19 +00:00
# jni.h expects jni_md.h to be in the header search path.
ln -s $out/include/${stdenv.hostPlatform.parsed.kernel.name}/*_md.h $out/include/
if [ -f $out/LICENSE ]; then
install -D $out/LICENSE $out/share/zulu/LICENSE
rm $out/LICENSE
fi
'';
preFixup = ''
2024-05-13 21:24:10 +00:00
# Propagate the setJavaClassPath setup hook from the ${
if isJdk8 then "JRE" else "JDK"
} so that
# any package that depends on the ${
if isJdk8 then "JRE" else "JDK"
} has $CLASSPATH set up
2024-05-02 00:46:19 +00:00
# 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
'' + lib.optionalString stdenv.isLinux ''
# We cannot use -exec since wrapProgram is a function but not a command.
#
# jspawnhelper is executed from JVM, so it doesn't need to wrap it, and it
# breaks building OpenJDK (#114495).
for bin in $( find "$out" -executable -type f -not -name jspawnhelper ); do
if patchelf --print-interpreter "$bin" &> /dev/null; then
wrapProgram "$bin" --prefix LD_LIBRARY_PATH : "${runtimeLibraryPath}"
fi
done
''
2024-05-13 21:24:10 +00:00
# FIXME: move all of the above to installPhase.
+ lib.optionalString stdenv.isLinux ''
find "$out" -name libfontmanager.so -exec \
patchelf --add-needed libfontconfig.so {} \;
'';
2024-05-02 00:46:19 +00:00
# fixupPhase is moving the man to share/man which breaks it because it's a
# relative symlink.
postFixup = lib.optionalString stdenv.isDarwin ''
2024-05-13 21:24:10 +00:00
ln -nsf ../zulu-${
lib.versions.major version
}.jdk/Contents/Home/man $out/share/man
2024-05-02 00:46:19 +00:00
'';
2024-05-13 21:24:10 +00:00
passthru = (lib.optionalAttrs isJdk8 { jre = jdk; }) // { home = jdk; };
2024-05-02 00:46:19 +00:00
meta = (import ../openjdk/meta.nix lib version) // {
description = "Certified builds of OpenJDK";
longDescription = ''
Certified builds of OpenJDK that can be deployed across multiple
operating systems, containers, hypervisors and Cloud platforms.
'';
homepage = "https://www.azul.com/products/zulu/";
mainProgram = "java";
maintainers = [ ];
platforms = builtins.attrNames dists;
2024-05-13 21:24:10 +00:00
sourceProvenance = with lib.sourceTypes; [
binaryBytecode
binaryNativeCode
];
2024-05-02 00:46:19 +00:00
};
};
2024-05-13 21:24:10 +00:00
in jdk