2016-07-19 07:48:36 +00:00
|
|
|
# Adaptation of the MIT-licensed work on `sbt2nix` done by Charles O'Farrell
|
|
|
|
|
2021-01-24 00:40:18 +00:00
|
|
|
{ lib, fetchurl, stdenv }:
|
2016-07-19 07:48:36 +00:00
|
|
|
let
|
|
|
|
defaultRepos = [
|
2020-12-11 10:43:23 +00:00
|
|
|
"https://repo1.maven.org/maven2"
|
|
|
|
"https://oss.sonatype.org/content/repositories/releases"
|
|
|
|
"https://oss.sonatype.org/content/repositories/public"
|
|
|
|
"https://repo.typesafe.com/typesafe/releases"
|
2016-07-19 07:48:36 +00:00
|
|
|
];
|
|
|
|
in
|
|
|
|
|
|
|
|
args@
|
|
|
|
{ # Example: "org.apache.httpcomponents"
|
|
|
|
groupId
|
|
|
|
, # Example: "httpclient"
|
|
|
|
artifactId
|
|
|
|
, # Example: "4.3.6"
|
|
|
|
version
|
2020-12-05 17:56:46 +00:00
|
|
|
, # Example: "jdk11"
|
|
|
|
classifier ? null
|
2016-07-19 07:48:36 +00:00
|
|
|
, # List of maven repositories from where to fetch the artifact.
|
|
|
|
# Example: [ http://oss.sonatype.org/content/repositories/public ].
|
|
|
|
repos ? defaultRepos
|
|
|
|
# The `url` and `urls` parameters, if specified should point to the JAR
|
|
|
|
# file and will take precedence over the `repos` parameter. Only one of `url`
|
|
|
|
# and `urls` can be specified, not both.
|
|
|
|
, url ? ""
|
|
|
|
, urls ? []
|
|
|
|
, # The rest of the arguments are just forwarded to `fetchurl`.
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
# only one of url and urls can be specified at a time.
|
|
|
|
assert (url == "") || (urls == []);
|
|
|
|
# if repos is empty, then url or urls must be specified.
|
|
|
|
assert (repos != []) || (url != "") || (urls != []);
|
|
|
|
|
|
|
|
let
|
|
|
|
name_ =
|
2021-01-24 00:40:18 +00:00
|
|
|
lib.concatStrings [
|
2022-12-12 01:36:03 +00:00
|
|
|
(lib.replaceStrings ["."] ["_"] groupId) "_"
|
|
|
|
(lib.replaceStrings ["."] ["_"] artifactId) "-"
|
2016-07-19 07:48:36 +00:00
|
|
|
version
|
|
|
|
];
|
|
|
|
mkJarUrl = repoUrl:
|
2021-01-24 00:40:18 +00:00
|
|
|
lib.concatStringsSep "/" [
|
|
|
|
(lib.removeSuffix "/" repoUrl)
|
2022-12-12 01:36:03 +00:00
|
|
|
(lib.replaceStrings ["."] ["/"] groupId)
|
2020-12-05 17:56:46 +00:00
|
|
|
artifactId
|
2016-07-19 07:48:36 +00:00
|
|
|
version
|
2021-01-24 00:40:18 +00:00
|
|
|
"${artifactId}-${version}${lib.optionalString (!isNull classifier) "-${classifier}"}.jar"
|
2016-07-19 07:48:36 +00:00
|
|
|
];
|
|
|
|
urls_ =
|
|
|
|
if url != "" then [url]
|
|
|
|
else if urls != [] then urls
|
|
|
|
else map mkJarUrl repos;
|
|
|
|
jar =
|
|
|
|
fetchurl (
|
2020-12-05 17:56:46 +00:00
|
|
|
builtins.removeAttrs args ["groupId" "artifactId" "version" "classifier" "repos" "url" ]
|
|
|
|
// { urls = urls_; name = "${name_}.jar"; }
|
2016-07-19 07:48:36 +00:00
|
|
|
);
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = name_;
|
|
|
|
phases = "installPhase fixupPhase";
|
|
|
|
# By moving the jar to $out/share/java we make it discoverable by java
|
|
|
|
# packages packages that mention this derivation in their buildInputs.
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/share/java
|
2020-12-05 17:56:46 +00:00
|
|
|
ln -s ${jar} $out/share/java/${artifactId}-${version}.jar
|
2016-07-19 07:48:36 +00:00
|
|
|
'';
|
|
|
|
# We also add a `jar` attribute that can be used to easily obtain the path
|
|
|
|
# to the downloaded jar file.
|
|
|
|
passthru.jar = jar;
|
|
|
|
}
|