Skip to content

fetchMavenArtifact: fix metadata support#433975

Merged
Lassulus merged 1 commit intoNixOS:masterfrom
vog:fetchmavenartifact-add-meta
Aug 20, 2025
Merged

fetchMavenArtifact: fix metadata support#433975
Lassulus merged 1 commit intoNixOS:masterfrom
vog:fetchmavenartifact-add-meta

Conversation

@vog
Copy link
Copy Markdown
Contributor

@vog vog commented Aug 15, 2025

Fix fetchMavenArtifact to forward the "meta" attribute to mkDerivation rather than fetchurl.

By fixing that issue, it adds support for the "meta" attribute of fetchMavenArtifact, making it usable as direct replacement for stdenv.mkDerivation in most cases.

Background: For many Java packages, the derivation created by fetchMavenArtifact is wrapped into another derivation that copies over all files, just to be able to specify the metadata via the "meta" attribute in the outer derivation. This is cumbersome, because it is extra code that is unnecessarily convoluted. And it is wasteful, as all downloaded JAR files are stored twice into the Nix store, for the outer and the inner derivation, until the next "gc" or "optimize" action happens.

Solution: All those derivations could instead be created by a single call to fetchMavenArtifact, without copying their downloaded JAR files twice into the Nix store, if fetchMavenArtifact would just forward the "meta" attribute properly. This commit does exactly that.

See PR #427538 for an example on how simple Java derivations from Maven Artifacts can be:

{ fetchMavenArtifact, lib }:
fetchMavenArtifact {
  groupId = "...";
  artifactId = "...";
  version = "...";
  hash = "sha256-...";
  meta = {
    homepage = "....";
    description = "...";
    license = ...;
    sourceProvenance = [ lib.sourceTypes.binaryBytecode ];
    maintainers = [ ... ];
  };
}

Also, reusing pieces of another package, such as its version number or most of it metadata, works the exact same way as we are used to with stdenv.mkDerivation:

{ fetchMavenArtifact, lib, some-other-package }:
fetchMavenArtifact {
  groupId = "...";
  artifactId = "...";
  inherit (some-other-package) version;
  hash = "sha256-...";
  meta = some-other-package.meta // {
    description = "...";
    sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
  };
}

Again, see PR #427538 for a practical example of reusing metadata.

Things done


Add a 👍 reaction to pull requests you find important.

@nix-owners nix-owners bot requested a review from philiptaron August 15, 2025 12:36
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 6.topic: fetch Fetchers (e.g. fetchgit, fetchsvn, ...) labels Aug 15, 2025
@vog vog requested review from Infinidoge and NickCao August 15, 2025 12:43
@msgilligan msgilligan mentioned this pull request Aug 15, 2025
13 tasks
Fix fetchMavenArtifact to forward the "meta" attribute to mkDerivation
rather than fetchurl.
@vog vog force-pushed the fetchmavenartifact-add-meta branch from 48021e5 to f81a2df Compare August 19, 2025 07:49
@vog vog changed the title fetchMavenArtifact: add metadata support fetchMavenArtifact: fix metadata support Aug 19, 2025
@Lassulus Lassulus merged commit 91d1792 into NixOS:master Aug 20, 2025
27 of 29 checks passed
@nixpkgs-ci
Copy link
Copy Markdown
Contributor

nixpkgs-ci bot commented Aug 20, 2025

Successfully created backport PR for release-25.05:

@github-actions github-actions bot added the 8.has: port to stable This PR already has a backport to the stable release. label Aug 20, 2025
@vog vog deleted the fetchmavenartifact-add-meta branch September 7, 2025 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: fetch Fetchers (e.g. fetchgit, fetchsvn, ...) 8.has: port to stable This PR already has a backport to the stable release. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants