Hi!
I’ve been trying to create a derivation for jmc. So the first thing I did was using BuildMavenPackage, but then realized I need to write a toolchains.xml
file so I created a new derivation to replace build-maven-package.nix
, this is the code I ended up with:
# nix-build --keep-failed maven.nix
let
pkgs = import <nixpkgs> { };
lib = pkgs.lib;
buildOffline = false;
stdenv = pkgs.stdenv;
jdk = pkgs.jdk;
manualMvnArtifacts = [ ];
manualMvnSources = [ ];
mvnHash = "";
mvnDepsParameters = "";
mvnSkipTests = "-DskipTests";
mvnParameters = "";
maven = pkgs.maven;
jdk17 = pkgs.jdk17;
pname = "jmc";
version = "1.2.1";
src = pkgs.fetchFromGitHub {
owner = "openjdk";
repo = pname;
rev = "cf85dbcb3872bd31c7d8145833eacda148455b3e";
hash = "sha256-d95b0sTLn6DHkh2SFAXTmiLr1INEF/UDxsIWF5E5yJY=";
};
in
stdenv.mkDerivation ({
name = "${pname}-${version}-maven-deps";
inherit src;
nativeBuildInputs = [
maven
];
JAVA_HOME = jdk;
JAVA_17HOME = jdk17;
NIX_DEBUG = 7;
buildPhase = ''
echo "Hello fetchedMavenDeps buildPhase"
runHook preBuild
mkdir -p $out/.m2
cat >$out/.m2/toolchains.xml <<EOL
<?xml version="1.0" encoding="UTF-8"?>
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<id>JavaSE-17</id>
<version>17</version>
<vendor>openjdk</vendor> <!-- or oracle depending on your setup -->
</provides>
<configuration>
<jdkHome>${jdk17.outPath}/lib/openjdk</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<id>JavaSE-21</id>
<version>21</version>
<vendor>openjdk</vendor> <!-- or oracle depending on your setup -->
</provides>
<configuration>
<jdkHome>${jdk.outPath}/lib/openjdk</jdkHome>
</configuration>
</toolchain>
</toolchains>
EOL
echo COCONUT
cat $out/.m2/toolchains.xml
'' + lib.optionalString buildOffline ''
mvn de.qaware.maven:go-offline-maven-plugin:1.2.8:resolve-dependencies -Dmaven.repo.local=$out/.m2 ${mvnDepsParameters}
for artifactId in ${builtins.toString manualMvnArtifacts}
do
echo "downloading manual $artifactId"
mvn dependency:get -Dartifact="$artifactId" -Dmaven.repo.local=$out/.m2
done
for artifactId in ${builtins.toString manualMvnSources}
do
group=$(echo $artifactId | cut -d':' -f1)
artifact=$(echo $artifactId | cut -d':' -f2)
echo "downloading manual sources $artifactId"
mvn dependency:sources -DincludeGroupIds="$group" -DincludeArtifactIds="$artifact" -Dmaven.repo.local=$out/.m2
done
'' + lib.optionalString (!buildOffline) ''
mvn p2:site --file releng/third-party/pom.xml -Dmaven.repo.local=$out/.m2
mvn jetty:run --file releng/third-party/pom.xml -Dmaven.repo.local=$out/.m2 &
echo "WTFFF@@@"
mvn toolchains:display-discovered-jdk-toolchains -Dmaven.repo.local=$out/.m2
mvn toolchains:generate-jdk-toolchains-xml -Dmaven.repo.local=$out/.m2
cat $out/.m2/toolchains.xml
echo "MVN CLEAN INSTALL"
mvn --toolchains $out/.m2/toolchains.xml clean install --file core/pom.xml -Dmaven.repo.local=$out/.m2 -Dmaven.test.skip=true
echo "MVN DEPENDENCY"
mvn --toolchains $out/.m2/toolchains.xml dependency:resolve -Dmaven.repo.local=$out/.m2
echo "MVN PACKAGE"
mvn --toolchains $out/.m2/toolchains.xml package -Dmaven.repo.local=$out/.m2 ${mvnSkipTests} ${mvnParameters}
'' + ''
echo "Goodbye fetchedMavenDeps buildPhase"
runHook postBuild
'';
# keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside
installPhase = ''
echo "Hello fetchedMavenDeps installPhase"
runHook preInstall
find $out -type f \( \
-name \*.lastUpdated \
-o -name resolver-status.properties \
-o -name _remote.repositories \) \
-delete
echo "Goodbye fetchedMavenDeps installPhase"
runHook postInstall
'';
# don't do any fixup
dontFixup = true;
outputHashAlgo = if mvnHash != "" then null else "sha256";
outputHashMode = "recursive";
outputHash = mvnHash;
})
The build does print Goodbye fetchedMavenDeps installPhase
but at the end I get this message
error: illegal path references in fixed-output derivation '/nix/store/1zv31z9kh7ini8r6iz0lirhpfqj99r8q-jmc-1.2.1-maven-deps.drv'
I searched in nix’s source code for that ‘illegal’ line and rebuild nix to print what the contents of newInfo0.references
are. Which turn out to be
59flqcj6x3dxiwjavxkwrycamg0482yb-openjdk-21.0.3+9
xy53lk4001h814d7dwh8f52wcqxrn7rp-openjdk-17.0.11+9
Now I’m pretty much stuck, not knowing what to do with that information.