fetchFromGitHub: take passthru and enhance overriding

Take optional argument `passthru` for custom passthru attribute set.

Update the `meta` attribute via `<pkg>.overrideAttrs` instead of
attribute set update (`//`).

Attach attributes `owner`, `repo` and `rev` via `passthru` instead of
attribute set update.
This commit is contained in:
Yueh-Shun Li 2024-03-09 00:01:11 +08:00 committed by Abhiram
parent ff4126b6ba
commit ef1e2ef8c2

View file

@ -8,6 +8,7 @@ lib.makeOverridable (
, deepClone ? false, private ? false, forceFetchGit ? false , deepClone ? false, private ? false, forceFetchGit ? false
, sparseCheckout ? [] , sparseCheckout ? []
, githubBase ? "github.com", varPrefix ? null , githubBase ? "github.com", varPrefix ? null
, passthru ? { }
, meta ? { } , meta ? { }
, ... # For hash agility , ... # For hash agility
}@args: }@args:
@ -21,6 +22,9 @@ let
else builtins.unsafeGetAttrPos "rev" args else builtins.unsafeGetAttrPos "rev" args
); );
baseUrl = "https://${githubBase}/${owner}/${repo}"; baseUrl = "https://${githubBase}/${owner}/${repo}";
newPassthru = passthru // {
inherit rev owner repo;
};
newMeta = meta // { newMeta = meta // {
homepage = meta.homepage or baseUrl; homepage = meta.homepage or baseUrl;
} // lib.optionalAttrs (position != null) { } // lib.optionalAttrs (position != null) {
@ -57,16 +61,19 @@ let
fetcherArgs = (if useFetchGit fetcherArgs = (if useFetchGit
then { then {
inherit rev deepClone fetchSubmodules sparseCheckout; url = gitRepoUrl; inherit rev deepClone fetchSubmodules sparseCheckout; url = gitRepoUrl;
passthru = newPassthru;
} // lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; } } // lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; }
else { else {
url = "${baseUrl}/archive/${rev}.tar.gz"; url = "${baseUrl}/archive/${rev}.tar.gz";
passthru = { passthru = newPassthru // {
inherit gitRepoUrl; inherit gitRepoUrl;
}; };
} }
) // privateAttrs // passthruAttrs // { inherit name; }; ) // privateAttrs // passthruAttrs // { inherit name; };
in in
fetcher fetcherArgs // { meta = newMeta; inherit rev owner repo; } (fetcher fetcherArgs).overrideAttrs (finalAttrs: previousAttrs: {
meta = newMeta;
})
) )