14 # Each Corretto version is based on a corresponding OpenJDK version. So
15 # building Corretto is more or less the same as building OpenJDK. Hence, the
16 # Corretto derivation overrides the corresponding OpenJDK derivation in order
17 # to have access to all the version-specific fixes for the various OpenJDK
18 # builds. However, Corretto uses `gradle` as build tool (which in turn will
19 # invoke `make`). The configure/build phases are adapted as needed.
24 # The version scheme is different between OpenJDK & Corretto.
25 # See https://github.com/corretto/corretto-17/blob/release-17.0.8.8.1/build.gradle#L40
26 # "major.minor.security.build.revision"
28 finalAttrs: oldAttrs: {
29 inherit pname version src;
30 name = "${pname}-${version}";
32 nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [
42 extra_config = builtins.concatStringsSep " " extraConfig;
45 # The rpm/deb task definitions require a Gradle plugin which we don't
46 # have and so the build fails. We'll simply remove them here because
47 # they are not needed anyways.
48 rm -rf installers/linux/universal/{rpm,deb}
50 # `/usr/bin/rsync` is invoked to copy the source tree. We don't have that.
51 for file in $(find installers -name "build.gradle"); do
52 substituteInPlace $file --replace-warn "workingDir '/usr/bin'" "workingDir '.'"
55 gradleFlagsArray+=(-Pcorretto.extra_config="${extra_config}")
58 # since we dontConfigure, we must run this manually
59 preBuild = "gradleConfigureHook";
61 # The Linux installer is placed at linux/universal/tar whereas the MacOS
64 if stdenv.hostPlatform.isDarwin then
65 ":installers:mac:tar:build"
67 ":installers:linux:universal:tar:packageBuildResults";
71 # Prepare for the installPhase so that it looks like if a normal
72 # OpenJDK had been built.
73 dir=build/jdkImageName/images
75 file=$(find ./installers -name 'amazon-corretto-${version}*.tar.gz')
76 tar -xzf $file -C $dir
77 mv $dir/amazon-corretto-* $dir/jdk
79 + oldAttrs.postBuild or "";
84 # The installPhase will place everything in $out/lib/openjdk and
85 # reference through symlinks. We don't rewrite the installPhase but at
86 # least move the folder to convey that this is not OpenJDK anymore.
87 mv $out/lib/openjdk $out/lib/corretto
88 ln -s $out/lib/corretto $out/lib/openjdk
93 pkg = finalAttrs.finalPackage;
98 version = testers.testVersion { package = pkg; };
99 vendor = runCommand "${pname}-vendor" { nativeBuildInputs = [ pkg ]; } ''
100 output=$(${pkg.meta.mainProgram} -XshowSettings:properties -version 2>&1 | grep vendor)
101 grep -Fq "java.vendor = Amazon.com Inc." - <<< "$output" && touch $out
103 compiler = runCommand "${pname}-compiler" { nativeBuildInputs = [ pkg ]; } ''
104 cat << EOF > Main.java
106 public static void main(String[] args) {
107 System.out.println("Hello, World!");
111 ${pkg}/bin/javac Main.java
112 ${pkg}/bin/java Main | grep -q "Hello, World!" && touch $out
117 # Some of the OpenJDK derivation set their `pos` by hand. We need to
118 # overwrite this in order to point to Corretto, not OpenJDK.
124 homepage = "https://aws.amazon.com/corretto";
125 license = licenses.gpl2Only;
126 description = "Amazon's distribution of OpenJDK";
127 maintainers = with maintainers; [ rollf ];