Closed stuebinm closed 4 months ago
I've added some tests, which should hopefully cover all uses of npins add git
which actually occur. Incidentally, they already helped me find a bug in my initial commit, so seems like having them is definitely worthwhile :)
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 https://github.com/andir/npins/issues/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.