nixpkgs/pkgs/build-support/fetchmavenartifact/default.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

94 lines
2.4 KiB
Nix

# Adaptation of the MIT-licensed work on `sbt2nix` done by Charles O'Farrell
{
lib,
fetchurl,
stdenv,
}:
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
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.
# 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
pname =
(lib.replaceStrings [ "." ] [ "_" ] groupId)
+ "_"
+ (lib.replaceStrings [ "." ] [ "_" ] artifactId);
suffix = lib.optionalString (classifier != null) "-${classifier}";
filename = "${artifactId}-${version}${suffix}.jar";
mkJarUrl =
repoUrl:
lib.concatStringsSep "/" [
(lib.removeSuffix "/" repoUrl)
(lib.replaceStrings [ "." ] [ "/" ] groupId)
artifactId
version
filename
];
urls_ =
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";
}
);
in
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;
}