feat: Get java builds working

This commit is contained in:
Nathan McCarty 2021-12-17 06:50:04 -05:00
parent 1199449a88
commit 60ec7b5e22
Signed by: thatonelutenist
GPG Key ID: D70DA3DD4D1E9F96
5 changed files with 120 additions and 13 deletions

View File

@ -10,13 +10,31 @@
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"utils": "utils"
}
},
"utils": {
"locked": {
"lastModified": 1638122382,
"narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "74f7e4319258e287b0f9cb95426c9853b282730b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},

102
flake.nix
View File

@ -1,11 +1,99 @@
{
description = "A very basic flake";
outputs = { self, nixpkgs }: {
packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
defaultPackage.x86_64-linux = self.packages.x86_64-linux.hello;
description = "Adoptium Java";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, utils }:
utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
sources = builtins.fromJSON (builtins.readFile ./sources.json);
in
with import nixpkgs { system = system; };
{
packages.jdks = builtins.mapAttrs
(name: value:
let
cpuName = stdenv.hostPlatform.parsed.cpu.name;
runtimeDependencies = [
pkgs.cups
pkgs.cairo
pkgs.glib
pkgs.gtk3
];
runtimeLibraryPath = lib.makeLibraryPath runtimeDependencies;
in
stdenv.mkDerivation rec {
name = "jdk${value.version}";
src = builtins.fetchurl {
url = value.url;
sha256 = value.sha256;
};
version = value.version;
buildInputs = with pkgs; [
alsa-lib
fontconfig
freetype
stdenv.cc.cc.lib
xorg.libX11
xorg.libXext
xorg.libXi
xorg.libXrender
xorg.libXtst
zlib
];
nativeBuildInputs = with pkgs; [
autoPatchelfHook
makeWrapper
];
dontStrip = 1;
installPhase = ''
cd ..
mv $sourceRoot $out
# jni.h expects jni_md.h to be in the header search path.
ln -s $out/include/linux/*_md.h $out/include/
rm -rf $out/demo
# Remove some broken manpages.
rm -rf $out/man/ja*
# Remove embedded freetype to avoid problems like
# https://github.com/NixOS/nixpkgs/issues/57733
find "$out" -name 'libfreetype.so*' -delete
# 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
# 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
'';
preFixup = ''
find "$out" -name libfontmanager.so -exec \
patchelf --add-needed libfontconfig.so {} \;
'';
}
)
sources.${system}.versions;
packages.jdk = self.packages.jdks.18;
packages.jdk-lts = self.packages.jdks.17;
packages.jdk18 = self.packages.jdks.18;
packages.jdk17 = self.packages.jdks.17;
packages.jdk16 = self.packages.jdks.16;
packages.jdk11 = self.packages.jdks.11;
defaultPackage = self.packages.jdks.18;
});
}

1
result Symbolic link
View File

@ -0,0 +1 @@
/nix/store/j8c42s14ri5kryqz5fjcjqd736z73bpi-jdk11.0.13+8

View File

@ -1,5 +1,5 @@
{
"x86_64-unknown-linux-gnu": {
"x86_64-linux": {
"versions": {
"17": {
"major_version": "17",

View File

@ -30,7 +30,7 @@ fn main() -> Result<()> {
sources.add_release(&version, &url)?;
}
let mut output: HashMap<String, Sources> = HashMap::new();
output.insert("x86_64-unknown-linux-gnu".to_string(), sources);
output.insert("x86_64-linux".to_string(), sources);
let json_output =
serde_json::to_string_pretty(&output).context("Failed to serialize output")?;
println!("{}", json_output);