nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 96 lines 2.5 kB view raw
1# Adaptation of the MIT-licensed work on `sbt2nix` done by Charles O'Farrell 2 3{ 4 lib, 5 fetchurl, 6 stdenv, 7}: 8let 9 defaultRepos = [ 10 "https://repo1.maven.org/maven2" 11 "https://oss.sonatype.org/content/repositories/releases" 12 "https://oss.sonatype.org/content/repositories/public" 13 "https://repo.typesafe.com/typesafe/releases" 14 ]; 15in 16 17args@{ 18 # Example: "org.apache.httpcomponents" 19 groupId, 20 # Example: "httpclient" 21 artifactId, 22 # Example: "4.3.6" 23 version, 24 # Example: "jdk11" 25 classifier ? null, 26 # List of maven repositories from where to fetch the artifact. 27 # Example: [ http://oss.sonatype.org/content/repositories/public ]. 28 repos ? defaultRepos, 29 # The `url` and `urls` parameters, if specified should point to the JAR 30 # file and will take precedence over the `repos` parameter. Only one of `url` 31 # and `urls` can be specified, not both. 32 url ? "", 33 urls ? [ ], 34 # Metadata 35 meta ? { }, 36 # The rest of the arguments are just forwarded to `fetchurl`. 37 ... 38}: 39 40# only one of url and urls can be specified at a time. 41assert (url == "") || (urls == [ ]); 42# if repos is empty, then url or urls must be specified. 43assert (repos != [ ]) || (url != "") || (urls != [ ]); 44 45let 46 pname = 47 (lib.replaceStrings [ "." ] [ "_" ] groupId) 48 + "_" 49 + (lib.replaceStrings [ "." ] [ "_" ] artifactId); 50 suffix = lib.optionalString (classifier != null) "-${classifier}"; 51 filename = "${artifactId}-${version}${suffix}.jar"; 52 mkJarUrl = 53 repoUrl: 54 lib.concatStringsSep "/" [ 55 (lib.removeSuffix "/" repoUrl) 56 (lib.replaceStrings [ "." ] [ "/" ] groupId) 57 artifactId 58 version 59 filename 60 ]; 61 urls_ = 62 if url != "" then 63 [ url ] 64 else if urls != [ ] then 65 urls 66 else 67 map mkJarUrl repos; 68 jar = fetchurl ( 69 removeAttrs args [ 70 "groupId" 71 "artifactId" 72 "version" 73 "classifier" 74 "repos" 75 "url" 76 "meta" 77 ] 78 // { 79 urls = urls_; 80 name = "${pname}-${version}.jar"; 81 } 82 ); 83in 84stdenv.mkDerivation { 85 inherit pname version meta; 86 dontUnpack = true; 87 # By moving the jar to $out/share/java we make it discoverable by java 88 # packages packages that mention this derivation in their buildInputs. 89 installPhase = '' 90 mkdir -p $out/share/java 91 ln -s ${jar} $out/share/java/${filename} 92 ''; 93 # We also add a `jar` attribute that can be used to easily obtain the path 94 # to the downloaded jar file. 95 passthru.jar = jar; 96}