diff options
author | Renzo Carbonara <k0001@users.noreply.github.com> | 2016-07-19 04:48:36 -0300 |
---|---|---|
committer | Franz Pletz <fpletz@fnordicwalking.de> | 2016-07-19 09:48:36 +0200 |
commit | e54ec2f907e8980027ba040f11375adac478cc84 (patch) | |
tree | a5787ce172ad189b0cfd5c7e652cac3697c1a075 /pkgs/build-support/fetchmavenartifact/default.nix | |
parent | 3530f3f20a934ed1d3df35fe3c8041d197f8b41e (diff) |
fetchMavenArtifact: init (#16825)
fetchMavenArtifact downloads a Maven artifact given a group id, an artifact id, and a version. Example usage: org_apache_httpcomponents_httpclient_4_5_2 = fetchMavenArtifact { groupId = "org.apache.httpcomponents"; artifactId = "httpclient"; version = "4.5.2"; sha256 = "0ms00zc28pwqk83nwwbafhq6p8zci9mrjzbqalpn6v0d80hwdzqd"; # Optionally: repos = [ ... urls to some Maven repos to use ... ]; # Optionally: url, urls - pointing directly to a specific jar url. }; Now `org_apache_httpcomponents_httpclient_4_5_2.jar` points to the downloaded JAR file, while `org_apache_httpcomponents_httpclient_4_5_2` refers to a derivation that when used used in `buildInputs` will be automatically added to the Java classpath.
Diffstat (limited to 'pkgs/build-support/fetchmavenartifact/default.nix')
-rw-r--r-- | pkgs/build-support/fetchmavenartifact/default.nix | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/pkgs/build-support/fetchmavenartifact/default.nix b/pkgs/build-support/fetchmavenartifact/default.nix new file mode 100644 index 0000000000000..a9c53249ae81c --- /dev/null +++ b/pkgs/build-support/fetchmavenartifact/default.nix @@ -0,0 +1,75 @@ +# Adaptation of the MIT-licensed work on `sbt2nix` done by Charles O'Farrell + +{ fetchurl, stdenv }: +let + defaultRepos = [ + http://central.maven.org/maven2 + http://oss.sonatype.org/content/repositories/releases + http://oss.sonatype.org/content/repositories/public + http://repo.typesafe.com/typesafe/releases + ]; +in + +args@ +{ # Example: "org.apache.httpcomponents" + groupId +, # Example: "httpclient" + artifactId +, # Example: "4.3.6" + version +, # 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_ = + with stdenv.lib; concatStrings [ + (replaceChars ["."] ["_"] groupId) "_" + (replaceChars ["."] ["_"] artifactId) "-" + version + ]; + mkJarUrl = repoUrl: + with stdenv.lib; concatStringsSep "/" [ + (removeSuffix "/" repoUrl) + (replaceChars ["."] ["/"] groupId) + artifactId + version + "${artifactId}-${version}.jar" + ]; + urls_ = + if url != "" then [url] + else if urls != [] then urls + else map mkJarUrl repos; + jar = + fetchurl ( + builtins.removeAttrs args ["groupId" "artifactId" "version" "repos" "url" ] + // { urls = urls_; name = "${name_}.jar"; } + ); +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 + ln -s ${jar} $out/share/java + ''; + # We also add a `jar` attribute that can be used to easily obtain the path + # to the downloaded jar file. + passthru.jar = jar; + } |