Fetchgit vs fetchGit

I’m suffering from cognitive overload in Nix. Do you have a quick answer to the question:

Should I be using pkgs.fetchgit or builtins.fetchGit?

More involved background information would be welcome too, for future reference, but in the short term I just need simple, actionable advice on which to use.

Also, is it better to use fetchFrom<service> (e.g. fetchFromGitHub) or just use fetch{g,G}it everywhere?

  • builtins.fetchGit performs the fetching during eval-time, and is primarily meant for fetching Nix expressions. It also allows for fetching private repositories.
  • pkgs.fetchgit is for during build-time and outputs a fixed-output derivation. It does not (properly) support fetching private repositories.

To add on, I think that the general advice is to use pkgs.fetchgit when you can, and only fall back to builtins.fetchGit when necessary.

Examples of times when builtins.fetchGit is necessary:

  • You’re pulling in a private repository.
  • You don’t have a nixpkgs imported yet in the Nix expression you’re writing.

This is not true. You can use netrc but it is a bit finique.

Also if you can use the fetchFromXxx (e.g. for github) it’s certainly better. fetchFromGithub will populate meta.homepage if needed, and use the tar zip archive if possible (I guess it’s faster? Also the source says that the hash is more stable with the tar.), and fallback to fetchgit otherwise (for advanced options).


Which you shouldn’t use and IMO we should remove because it is super annoying when reviewing because you don’t have a link to click or copy.

It is using a zip download.

It is faster in many cases than git cloning.

1 Like

Thanks for the precision! I corrected the zip/tar error.