fetchMavenArtifact: support artifact classifier syntax

This commit is contained in:
hlolli 2020-11-14 00:55:44 +01:00
parent c1dfbaa8ad
commit 49c789703c
No known key found for this signature in database
GPG key ID: 4B0F0A72A77F2CED

View file

@ -36,19 +36,28 @@ assert (repos != []) || (url != "") || (urls != []);
let
classifierSplit =
with stdenv.lib.strings;
splitString "$" artifactId;
artifactId_ = builtins.head classifierSplit;
classifier =
with stdenv.lib;
if builtins.length classifierSplit > 1
then concatStrings ["-" (builtins.elemAt classifierSplit 1)]
else "";
name_ =
with stdenv.lib; concatStrings [
(replaceChars ["."] ["_"] groupId) "_"
(replaceChars ["."] ["_"] artifactId) "-"
(replaceChars ["."] ["_"] artifactId_) "-"
version
];
mkJarUrl = repoUrl:
with stdenv.lib; concatStringsSep "/" [
(removeSuffix "/" repoUrl)
(replaceChars ["."] ["/"] groupId)
artifactId
artifactId_
version
"${artifactId}-${version}.jar"
"${artifactId_}-${version}${classifier}.jar"
];
urls_ =
if url != "" then [url]
@ -57,7 +66,7 @@ let
jar =
fetchurl (
builtins.removeAttrs args ["groupId" "artifactId" "version" "repos" "url" ]
// { urls = urls_; name = "${name_}.jar"; }
// { urls = urls_; name = "${name_}${classifier}.jar"; }
);
in
stdenv.mkDerivation {
@ -67,7 +76,7 @@ in
# packages packages that mention this derivation in their buildInputs.
installPhase = ''
mkdir -p $out/share/java
ln -s ${jar} $out/share/java/${artifactId}-${version}.jar
ln -s ${jar} $out/share/java/${artifactId_}-${version}${classifier}.jar
'';
# We also add a `jar` attribute that can be used to easily obtain the path
# to the downloaded jar file.