2019-06-04 16:50:29 +00:00
|
|
|
{ stdenv, lib, writeShellScriptBin, fetchurl }:
|
|
|
|
|
|
|
|
# Put the downloaded files in a fake Maven repository
|
|
|
|
name: source:
|
|
|
|
|
|
|
|
let
|
2019-09-07 12:57:22 +00:00
|
|
|
inherit (lib)
|
|
|
|
removeSuffix optionalString splitString concatMapStrings
|
|
|
|
attrByPath attrValues last makeOverridable;
|
|
|
|
|
|
|
|
# some .jar files have an `-aot` suffix that doesn't work for .pom files
|
|
|
|
getPOM = jarUrl: "${removeSuffix "-aot" jarUrl}.pom";
|
|
|
|
|
2019-06-04 16:50:29 +00:00
|
|
|
script = writeShellScriptBin "create-local-maven-repo" (''
|
|
|
|
mkdir -p $out
|
|
|
|
cd $out
|
|
|
|
'' +
|
2019-09-07 12:57:22 +00:00
|
|
|
(concatMapStrings (dep':
|
2019-06-04 16:50:29 +00:00
|
|
|
let
|
|
|
|
dep = { postCopy = ""; } // dep';
|
|
|
|
url = "${dep.host}/${dep.path}";
|
|
|
|
pom = {
|
2019-09-07 12:57:22 +00:00
|
|
|
sha1 = attrByPath [ "pom" "sha1" ] "" dep;
|
|
|
|
sha256 = attrByPath [ "pom" "sha256" ] "" dep;
|
2019-06-04 16:50:29 +00:00
|
|
|
};
|
2019-09-07 12:57:22 +00:00
|
|
|
pom-download = optionalString (pom.sha256 != "") (
|
|
|
|
fetchurl { url = getPOM url; inherit (pom) sha256; }
|
|
|
|
);
|
2019-06-04 16:50:29 +00:00
|
|
|
jar = {
|
2019-09-07 12:57:22 +00:00
|
|
|
sha1 = attrByPath [ "jar" "sha1" ] "" dep;
|
|
|
|
sha256 = attrByPath [ "jar" "sha256" ] "" dep;
|
2019-06-04 16:50:29 +00:00
|
|
|
};
|
2019-09-07 12:57:22 +00:00
|
|
|
jar-download = optionalString (jar.sha256 != "") (
|
|
|
|
fetchurl { url = "${url}.${dep.type}"; inherit (jar) sha256; }
|
|
|
|
);
|
|
|
|
fileName = last (splitString "/" dep.path);
|
|
|
|
directory = removeSuffix fileName dep.path;
|
2019-06-04 16:50:29 +00:00
|
|
|
in
|
|
|
|
''
|
|
|
|
mkdir -p ${directory}
|
|
|
|
|
2019-09-07 12:57:22 +00:00
|
|
|
${optionalString (pom-download != "") ''
|
2020-05-04 19:20:53 +00:00
|
|
|
ln -s "${pom-download}" "${getPOM dep.path}"
|
2019-06-04 16:50:29 +00:00
|
|
|
''}
|
2019-09-07 12:57:22 +00:00
|
|
|
${optionalString (pom.sha1 != "") ''
|
|
|
|
echo "${pom.sha1}" > "${getPOM dep.path}.sha1"
|
2019-06-04 16:50:29 +00:00
|
|
|
''}
|
2019-09-07 12:57:22 +00:00
|
|
|
${optionalString (jar-download != "") ''
|
2020-05-04 19:20:53 +00:00
|
|
|
ln -s "${jar-download}" "${dep.path}.${dep.type}"
|
2019-06-04 16:50:29 +00:00
|
|
|
''}
|
2019-09-07 12:57:22 +00:00
|
|
|
${optionalString (jar.sha1 != "") ''
|
2019-06-04 16:50:29 +00:00
|
|
|
echo "${jar.sha1}" > "${dep.path}.${dep.type}.sha1"
|
|
|
|
''}
|
|
|
|
|
|
|
|
${if dep.postCopy != "" then ''
|
|
|
|
depPath="$PWD/${dep.path}"
|
2020-05-04 19:20:53 +00:00
|
|
|
# postCopy can't modify the jar if it's a symlink
|
|
|
|
rm "${dep.path}.${dep.type}"
|
|
|
|
cp "${jar-download}" "${dep.path}.${dep.type}"
|
2019-06-04 16:50:29 +00:00
|
|
|
${dep.postCopy}
|
|
|
|
unset depPath
|
|
|
|
'' else ""
|
|
|
|
}
|
|
|
|
'')
|
2019-09-07 12:57:22 +00:00
|
|
|
(attrValues source)));
|
2019-06-04 16:50:29 +00:00
|
|
|
|
2019-09-07 12:57:22 +00:00
|
|
|
in makeOverridable stdenv.mkDerivation {
|
2019-06-04 16:50:29 +00:00
|
|
|
inherit name;
|
|
|
|
phases = [ "buildPhase" ];
|
|
|
|
buildPhase = "${script}/bin/create-local-maven-repo";
|
|
|
|
}
|