andir / npins

Nix dependency pinning. Very similar to Niv but has a few features that I personally wanted.
European Union Public License 1.2
194 stars 16 forks source link

builtins.fetchGit: use same name as nix-prefetch-git #74

Closed stuebinm closed 4 months ago

stuebinm commented 5 months ago

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.

stuebinm commented 5 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 :)