Difference between fetchtarball fetchfromgithub fetchgit?

is fetchgit just fetchtarball but optmized for git? (so i should always use it if possible?)
what does fetchgithub do over fetchgit?

and, suppose there is a repo on github that provide default.nix, how can i import that repo into my own project managed using nix? should i fetchgithub it, and add the result into buildinput?

2 Likes

fetchgit fetches using git. It doesn’t fetch a tarball (arbitrary git repos don’t vend tarballs). It also fetches submodules by default, and can optionally do a deep clone. You can read the implementation, along with its builder script, and the actual script that does the fetch.

fetchFromGitHub on the other hand does end up being a call to fetchzip in most cases. It only uses fetchgit if you specify fetchSubmodules = true (which, unlike fetchgit, defaults to false). It also is more convenient to use, and supports private GitHub instances as well. The implementation is pretty simple.

If you’re fetching from GitHub, you should use fetchFromGitHub. It’s the easiest to use and will do the right thing.

I just learned recently that there’s a feature called Import From Derivation, where you can create a derivation and then pass that to import and it will build the derivation, then import the resulting out path. This might do what you want, where the imported derivation is a call to fetchGitHub. Note that IFD is disabled on Hydra (there’s a nix.conf key called allow-import-from-derivation).

Also if you are going to go this route, then you should provide a fixed output hash to fetchGitHub (assuming you’re fetching a revision/tag, rather than a branch), otherwise it will have to re-fetch every time you try to evaluate the imported derivation.

5 Likes