about summary refs log tree commit diff
path: root/nixpkgs/pkgs/build-support/fetchmavenartifact/default.nix
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-01-07 02:18:36 +0000
committerAlyssa Ross <hi@alyssa.is>2019-01-07 02:18:47 +0000
commit36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2 (patch)
treeb3faaf573407b32aa645237a4d16b82778a39a92 /nixpkgs/pkgs/build-support/fetchmavenartifact/default.nix
parent4e31070265257dc67d120c27e0f75c2344fdfa9a (diff)
parentabf060725d7614bd3b9f96764262dfbc2f9c2199 (diff)
downloadnixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.gz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.bz2
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.lz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.xz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.zst
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.zip
Add 'nixpkgs/' from commit 'abf060725d7614bd3b9f96764262dfbc2f9c2199'
git-subtree-dir: nixpkgs
git-subtree-mainline: 4e31070265257dc67d120c27e0f75c2344fdfa9a
git-subtree-split: abf060725d7614bd3b9f96764262dfbc2f9c2199
Diffstat (limited to 'nixpkgs/pkgs/build-support/fetchmavenartifact/default.nix')
-rw-r--r--nixpkgs/pkgs/build-support/fetchmavenartifact/default.nix75
1 files changed, 75 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/build-support/fetchmavenartifact/default.nix b/nixpkgs/pkgs/build-support/fetchmavenartifact/default.nix
new file mode 100644
index 000000000000..dc48a312fb37
--- /dev/null
+++ b/nixpkgs/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/${artifactId}-${version}.jar
+    '';
+    # We also add a `jar` attribute that can be used to easily obtain the path
+    # to the downloaded jar file.
+    passthru.jar = jar;
+  }