add classifier as an argument

This commit is contained in:
hlolli 2020-12-05 18:56:46 +01:00
parent 49c789703c
commit 38ad378228
No known key found for this signature in database
GPG Key ID: 4B0F0A72A77F2CED

View File

@ -17,6 +17,8 @@ args@
artifactId artifactId
, # Example: "4.3.6" , # Example: "4.3.6"
version version
, # Example: "jdk11"
classifier ? null
, # List of maven repositories from where to fetch the artifact. , # List of maven repositories from where to fetch the artifact.
# Example: [ http://oss.sonatype.org/content/repositories/public ]. # Example: [ http://oss.sonatype.org/content/repositories/public ].
repos ? defaultRepos repos ? defaultRepos
@ -36,28 +38,19 @@ assert (repos != []) || (url != "") || (urls != []);
let 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_ = name_ =
with stdenv.lib; concatStrings [ with stdenv.lib; concatStrings [
(replaceChars ["."] ["_"] groupId) "_" (replaceChars ["."] ["_"] groupId) "_"
(replaceChars ["."] ["_"] artifactId_) "-" (replaceChars ["."] ["_"] artifactId) "-"
version version
]; ];
mkJarUrl = repoUrl: mkJarUrl = repoUrl:
with stdenv.lib; concatStringsSep "/" [ with stdenv.lib; concatStringsSep "/" [
(removeSuffix "/" repoUrl) (removeSuffix "/" repoUrl)
(replaceChars ["."] ["/"] groupId) (replaceChars ["."] ["/"] groupId)
artifactId_ artifactId
version version
"${artifactId_}-${version}${classifier}.jar" "${artifactId}-${version}-${optionalString (!isNull classifier) "-${classifier}"}.jar"
]; ];
urls_ = urls_ =
if url != "" then [url] if url != "" then [url]
@ -65,8 +58,8 @@ let
else map mkJarUrl repos; else map mkJarUrl repos;
jar = jar =
fetchurl ( fetchurl (
builtins.removeAttrs args ["groupId" "artifactId" "version" "repos" "url" ] builtins.removeAttrs args ["groupId" "artifactId" "version" "classifier" "repos" "url" ]
// { urls = urls_; name = "${name_}${classifier}.jar"; } // { urls = urls_; name = "${name_}.jar"; }
); );
in in
stdenv.mkDerivation { stdenv.mkDerivation {
@ -76,7 +69,7 @@ in
# packages packages that mention this derivation in their buildInputs. # packages packages that mention this derivation in their buildInputs.
installPhase = '' installPhase = ''
mkdir -p $out/share/java mkdir -p $out/share/java
ln -s ${jar} $out/share/java/${artifactId_}-${version}${classifier}.jar ln -s ${jar} $out/share/java/${artifactId}-${version}.jar
''; '';
# We also add a `jar` attribute that can be used to easily obtain the path # We also add a `jar` attribute that can be used to easily obtain the path
# to the downloaded jar file. # to the downloaded jar file.