core/pkgs/by-name/ja/java/adoptopenjdk-bin/jdk-linux-base.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

139 lines
3.4 KiB
Nix
Raw Normal View History

2024-05-02 00:46:19 +00:00
{
sourcePerArch,
knownVulnerabilities ? [ ],
}:
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
{
stdenv,
lib,
fetchurl,
autoPatchelfHook,
makeWrapper,
setJavaClassPath,
# minimum dependencies
alsa-lib,
fontconfig,
freetype,
libffi,
xorg,
zlib,
# runtime dependencies
cups,
# runtime dependencies for GTK+ Look and Feel
gtkSupport ? true,
cairo,
glib,
gtk3,
}:
let
cpuName = stdenv.hostPlatform.parsed.cpu.name;
runtimeDependencies =
[ cups ]
++ lib.optionals gtkSupport [
cairo
glib
gtk3
];
runtimeLibraryPath = lib.makeLibraryPath runtimeDependencies;
in
let
result = stdenv.mkDerivation rec {
pname =
if sourcePerArch.packageType == "jdk" then
"adoptopenjdk-${sourcePerArch.vmType}-bin"
else
"adoptopenjdk-${sourcePerArch.packageType}-${sourcePerArch.vmType}-bin";
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
version = sourcePerArch.${cpuName}.version or (throw "unsupported CPU ${cpuName}");
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
src = fetchurl { inherit (sourcePerArch.${cpuName}) url sha256; };
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
buildInputs = [
alsa-lib # libasound.so wanted by lib/libjsound.so
fontconfig
2024-06-30 08:16:52 +00:00
freetype
2024-05-02 00:46:19 +00:00
stdenv.cc.cc.lib # libstdc++.so.6
xorg.libX11
xorg.libXext
xorg.libXi
xorg.libXrender
xorg.libXtst
2024-06-30 08:16:52 +00:00
zlib
2024-05-02 00:46:19 +00:00
] ++ lib.optional stdenv.isAarch32 libffi;
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
nativeBuildInputs = [
autoPatchelfHook
makeWrapper
2024-06-30 08:16:52 +00:00
];
2024-05-02 00:46:19 +00:00
# See: https://github.com/NixOS/patchelf/issues/10
dontStrip = 1;
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
installPhase = ''
2024-06-30 08:16:52 +00:00
cd ..
2024-05-02 00:46:19 +00:00
mv $sourceRoot $out
2024-06-30 08:16:52 +00:00
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/linux/*_md.h $out/include/
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
rm -rf $out/demo
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
# Remove some broken manpages.
rm -rf $out/man/ja*
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
# Remove embedded freetype to avoid problems like
# https://github.com/NixOS/nixpkgs/issues/57733
find "$out" -name 'libfreetype.so*' -delete
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
# 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
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
# Set JAVA_HOME automatically.
cat <<EOF >> "$out/nix-support/setup-hook"
if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out; fi
2024-06-30 08:16:52 +00:00
EOF
2024-05-02 00:46:19 +00:00
# We cannot use -exec since wrapProgram is a function but not a command.
2024-06-30 08:16:52 +00:00
#
2024-05-02 00:46:19 +00:00
# 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}"
2024-06-30 08:16:52 +00:00
fi
done
'';
2024-05-02 00:46:19 +00:00
preFixup = ''
find "$out" -name libfontmanager.so -exec \
patchelf --add-needed libfontconfig.so {} \;
2024-06-30 08:16:52 +00:00
'';
2024-05-02 00:46:19 +00:00
# FIXME: use multiple outputs or return actual JRE package
passthru.jre = result;
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
passthru.home = result;
2024-06-30 08:16:52 +00:00
2024-05-02 00:46:19 +00:00
meta = with lib; {
license = licenses.gpl2Classpath;
sourceProvenance = with sourceTypes; [
binaryNativeCode
binaryBytecode
2024-06-30 08:16:52 +00:00
];
2024-05-02 00:46:19 +00:00
description = "AdoptOpenJDK, prebuilt OpenJDK binary";
platforms = lib.mapAttrsToList (arch: _: arch + "-linux") sourcePerArch; # some inherit jre.meta.platforms
maintainers = with lib.maintainers; [ taku0 ];
inherit knownVulnerabilities;
mainProgram = "java";
};
};
in
result