Skip to content

fetchFromGitHub: use passthru instead of // to support overrideAttrs #370418

@TomaSajt

Description

@TomaSajt

Describe the bug

Currently fetchFromGitHub works like this:

{ ... }:
let
  ...
  
  fetcherArgs = (if useFetchGit
    then {
      inherit tag rev deepClone fetchSubmodules sparseCheckout fetchLFS; url = gitRepoUrl;
    } // lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; }
    else {
      url = "${baseUrl}/archive/${revWithTag}.tar.gz";


      passthru = {
        inherit gitRepoUrl;
      };
    }
  ) // privateAttrs // passthruAttrs // { inherit name; };
in


fetcher fetcherArgs // { meta = newMeta; inherit owner repo tag; rev = revWithTag; }

(see the entire file: https://github.com/NixOS/nixpkgs/blob/edb546d0e3884c526dab475224136637cae3f36f/pkgs/build-support/fetchgithub/default.nix#L64C1-L78C85)

unfortunately, the last line is messing up the overrideAttrs interface: because // is used on the derivation itself overrideAttrs doesn't know about their existance and thus deletes them if we try to .overrideAttrs the result of fetchFromGitHub.

Possible solution

passthru is a method for achieving the same thing, aka. appending extra information onto a derivation, but from the inside. It's also supported by overrideAttrs.

If we did

passthru = {
  inherit gitRepoUrl owner repo tag;
  meta = newMeta;
  rev = revWithTag;
};

it would be much better, however fetchgit currently doesn't support passing passthru, so we'd also need to change that.
(Though, meta should probably not be part of passthru if we did this)

Note

I know there's a .override interface over fetchFromGitHub, however that's not "generic" enough. .overrideAttrs should work with any kind of fetcher.
It would be amazing if we could be able to do something like this and not have to worry about implementation details of the src FOD.

Example:

some-package.overrideAttrs (prevAttrs: {
  version = "2.0";
  src = prevAttrs.src.overrideAttrs { outputHash = "new-hash"; };
})

Notify maintainers


Note for maintainers: Please tag this issue in your PR.


Add a 👍 reaction to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions