# Difference between fetchtarball fetchfromgithub fetchgit?

**URL:** https://discourse.nixos.org/t/difference-between-fetchtarball-fetchfromgithub-fetchgit/3279
**Category:** Help
**Created:** [June 26, 2019, 1:38am UTC](https://discourse.nixos.org/t/difference-between-fetchtarball-fetchfromgithub-fetchgit/3279 "2019-06-26T01:38:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![MarisaKirisame](https://discourse.nixos.org/user_avatar/discourse.nixos.org/marisakirisame/32/1463_2.png) [@MarisaKirisame](https://discourse.nixos.org/u/MarisaKirisame)
#### Post date: [June 26, 2019, 1:38am UTC](https://discourse.nixos.org/t/difference-between-fetchtarball-fetchfromgithub-fetchgit/3279/1 "2019-06-26T01:38:43Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![lilyball](https://discourse.nixos.org/user_avatar/discourse.nixos.org/lilyball/32/939_2.png) [@lilyball](https://discourse.nixos.org/u/lilyball)
#### Post date: [June 26, 2019, 7:17am UTC](https://discourse.nixos.org/t/difference-between-fetchtarball-fetchfromgithub-fetchgit/3279/2 "2019-06-26T07:17:12Z")

</div>

> [@MarisaKirisame](#):
>
> is fetchgit just fetchtarball but optmized for git? (so i should always use it if possible?)  
> what does fetchgithub do over fetchgit?

`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](https://github.com/NixOS/nixpkgs/blob/40baa1f2de4abda35dc93d5dacedcccc2d72238a/pkgs/build-support/fetchgit/default.nix), along with its [builder script](https://github.com/NixOS/nixpkgs/blob/40baa1f2de4abda35dc93d5dacedcccc2d72238a/pkgs/build-support/fetchgit/builder.sh), and the actual [script that does the fetch](https://github.com/NixOS/nixpkgs/blob/40baa1f2de4abda35dc93d5dacedcccc2d72238a/pkgs/build-support/fetchgit/nix-prefetch-git).

`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](https://github.com/NixOS/nixpkgs/blob/40baa1f2de4abda35dc93d5dacedcccc2d72238a/pkgs/build-support/fetchgithub/default.nix) 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.

> [@MarisaKirisame](#):
>
> 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?

I just learned recently that there’s a feature called [Import From Derivation](https://nixos.wiki/wiki/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.
