builtins.fetchGit: use same name as nix-prefetch-git #74
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using npins with (generic, i.e. non-github) git repositories, we currently have the issue of having to download these twice: once while doing
npins add git ...
, and then a second time when evaluating the source attribute in Nix.The source of this is that
nix-prefetch-git
, which we use to get the hash, sets as name for the store path it produces a name derived from the url; this behaviour is not configurable. In contrast,builtins.fetchGit
sets the name as"source"
by default.The nixpkgs fetcher uses a nix implementation of the same logic to derive the desired name in nix.
This commit adds a function which does the same, derived from the one in Nixpkgs, but tweaked to only use builtin functions, and uses it to set an appropriate name for the git fetcher. With it, a the name exposed by npins to nix code changes to the one that
nix-prefetch-git
also used, thus we avoid this doubled download after adding a new source.This logic is somewhat delicate. I've added a safe guard so that if it ever fails to extract a name, we fall back to using
"source"
as attribute name.Note that while this is a similar issue to #57, it is (afaict, anyways) not related to
builtins.fetchGit
not using the fetcher cache. That's a separate issue which also causes doubled downloads.