2024-05-02 00:46:19 +00:00
|
|
|
# Adaptation of the MIT-licensed work on `sbt2nix` done by Charles O'Farrell
|
|
|
|
|
2024-06-30 08:16:52 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
fetchurl,
|
|
|
|
stdenv,
|
|
|
|
}:
|
2024-05-02 00:46:19 +00:00
|
|
|
let
|
|
|
|
defaultRepos = [
|
|
|
|
"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"
|
|
|
|
];
|
|
|
|
in
|
|
|
|
|
2024-06-30 08:16:52 +00:00
|
|
|
args@{
|
|
|
|
# Example: "org.apache.httpcomponents"
|
|
|
|
groupId,
|
|
|
|
# Example: "httpclient"
|
|
|
|
artifactId,
|
|
|
|
# Example: "4.3.6"
|
|
|
|
version,
|
|
|
|
# Example: "jdk11"
|
|
|
|
classifier ? null,
|
|
|
|
# List of maven repositories from where to fetch the artifact.
|
2024-05-02 00:46:19 +00:00
|
|
|
# Example: [ http://oss.sonatype.org/content/repositories/public ].
|
2024-06-30 08:16:52 +00:00
|
|
|
repos ? defaultRepos,
|
2024-05-02 00:46:19 +00:00
|
|
|
# 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.
|
2024-06-30 08:16:52 +00:00
|
|
|
url ? "",
|
|
|
|
urls ? [ ],
|
|
|
|
# The rest of the arguments are just forwarded to `fetchurl`.
|
2024-05-02 00:46:19 +00:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
# only one of url and urls can be specified at a time.
|
2024-06-30 08:16:52 +00:00
|
|
|
assert (url == "") || (urls == [ ]);
|
2024-05-02 00:46:19 +00:00
|
|
|
# if repos is empty, then url or urls must be specified.
|
2024-06-30 08:16:52 +00:00
|
|
|
assert (repos != [ ]) || (url != "") || (urls != [ ]);
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
let
|
2024-06-30 08:16:52 +00:00
|
|
|
pname =
|
|
|
|
(lib.replaceStrings [ "." ] [ "_" ] groupId)
|
|
|
|
+ "_"
|
|
|
|
+ (lib.replaceStrings [ "." ] [ "_" ] artifactId);
|
2024-05-02 00:46:19 +00:00
|
|
|
suffix = lib.optionalString (classifier != null) "-${classifier}";
|
|
|
|
filename = "${artifactId}-${version}${suffix}.jar";
|
2024-06-30 08:16:52 +00:00
|
|
|
mkJarUrl =
|
|
|
|
repoUrl:
|
2024-05-02 00:46:19 +00:00
|
|
|
lib.concatStringsSep "/" [
|
|
|
|
(lib.removeSuffix "/" repoUrl)
|
2024-06-30 08:16:52 +00:00
|
|
|
(lib.replaceStrings [ "." ] [ "/" ] groupId)
|
2024-05-02 00:46:19 +00:00
|
|
|
artifactId
|
|
|
|
version
|
|
|
|
filename
|
|
|
|
];
|
|
|
|
urls_ =
|
2024-06-30 08:16:52 +00:00
|
|
|
if url != "" then
|
|
|
|
[ url ]
|
|
|
|
else if urls != [ ] then
|
|
|
|
urls
|
|
|
|
else
|
|
|
|
map mkJarUrl repos;
|
|
|
|
jar = fetchurl (
|
|
|
|
builtins.removeAttrs args [
|
|
|
|
"groupId"
|
|
|
|
"artifactId"
|
|
|
|
"version"
|
|
|
|
"classifier"
|
|
|
|
"repos"
|
|
|
|
"url"
|
|
|
|
]
|
|
|
|
// {
|
|
|
|
urls = urls_;
|
|
|
|
name = "${pname}-${version}.jar";
|
|
|
|
}
|
|
|
|
);
|
2024-05-02 00:46:19 +00:00
|
|
|
in
|
2024-06-30 08:16:52 +00:00
|
|
|
stdenv.mkDerivation {
|
|
|
|
inherit pname version;
|
|
|
|
dontUnpack = true;
|
|
|
|
# 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
|
|
|
|
ln -s ${jar} $out/share/java/${filename}
|
|
|
|
'';
|
|
|
|
# We also add a `jar` attribute that can be used to easily obtain the path
|
|
|
|
# to the downloaded jar file.
|
|
|
|
passthru.jar = jar;
|
|
|
|
}
|