Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchMavenArtifact: support artifact classifier syntax #103755

Merged
merged 2 commits into from Dec 6, 2020

Conversation

hlolli
Copy link
Member

@hlolli hlolli commented Nov 14, 2020

Motivation for this change

On several occasions, users of clj2nix have reported problems with maven artifacts which include classifiers.
Outside of POM/xml, at least in clojure (altough I failed to find much information around this topic), classifiers
are specified by artifact name with dollar and the classifier name appended.

This will solve problems for clojure users using the official clojure cli tool with deps.edn, as well as java users who wish to
specify maven artifacts with specifiers.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@terlar
Copy link
Contributor

terlar commented Nov 28, 2020

I just ran into this myself, however I would suggest just adding the attribute, as the $ notation is a Clojure thing and I believe it should be handled in clj2nix instead. E.g. it should generate the attribute and strip the $ part. See:

From 16430125c3c720fa6025e6c4fc80118816b7fe3f Mon Sep 17 00:00:00 2001
From: Terje Larsen <terlar@gmail.com>
Date: Sat, 28 Nov 2020 16:07:05 +0100
Subject: [PATCH] fetchMavenArtifact: support classifier attribute

---
 pkgs/build-support/fetchmavenartifact/default.nix | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/build-support/fetchmavenartifact/default.nix b/pkgs/build-support/fetchmavenartifact/default.nix
index 583a9ea396c..42ad7603a8f 100644
--- a/pkgs/build-support/fetchmavenartifact/default.nix
+++ b/pkgs/build-support/fetchmavenartifact/default.nix
@@ -17,6 +17,8 @@ args@
   artifactId
 , # Example: "4.3.6"
   version
+, # Example: "jdk11"
+  classifier ? null
 , # List of maven repositories from where to fetch the artifact.
   # Example: [ http://oss.sonatype.org/content/repositories/public ].
   repos ? defaultRepos
@@ -48,7 +50,7 @@ let
       (replaceChars ["."] ["/"] groupId)
       artifactId
       version
-      "${artifactId}-${version}.jar"
+      "${artifactId}-${version}-${optionalString (!isNull classifier) "-${classifier}"}.jar"
     ];
   urls_ =
     if url != "" then [url]
@@ -56,7 +58,7 @@ let
     else map mkJarUrl repos;
   jar =
     fetchurl (
-      builtins.removeAttrs args ["groupId" "artifactId" "version" "repos" "url" ]
+      builtins.removeAttrs args ["groupId" "artifactId" "version" "classifier" "repos" "url" ]
         // { urls = urls_; name = "${name_}.jar"; }
     );
 in
-- 
2.28.0

Then with clj2nix it could be used as such:

    {
      name = "com.google.inject/guice";
      path = pkgs.fetchMavenArtifact {
        inherit repos;
        artifactId = "guice";
        groupId = "com.google.inject";
        sha512 =
          "9af46efaacfa911f4f337785ef75df2013eecc64af3842d10df97f453b84d0e7990d3e981c27f315184390355744f4b8857eb87b5a45e24549251da4c4d387d9";
        version = "4.0";
        classifier = "no_aop";
      };
    }

@hlolli
Copy link
Member Author

hlolli commented Dec 5, 2020

@terlar your patch works, I tested it with unpushed changes on clj2nix. While this will cause illegal argument, I'll most likely modify clj2nix to use fetchMavenArtifact from this pr when I push my changes there.

@terlar terlar requested a review from Mic92 December 5, 2020 20:15
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/397

@Mic92 Mic92 merged commit 1df84d1 into NixOS:master Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants