# Difference between \`fetchgit\` and \`fetchGit\`

**URL:** https://discourse.nixos.org/t/difference-between-fetchgit-and-fetchgit/3619
**Category:** Help
**Created:** [August 5, 2019, 12:42pm UTC](https://discourse.nixos.org/t/difference-between-fetchgit-and-fetchgit/3619 "2019-08-05T12:42:22Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ilikeavocadoes](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/i/848f3c/32.png) [@ilikeavocadoes](https://discourse.nixos.org/u/ilikeavocadoes)
#### Post date: [August 5, 2019, 12:42pm UTC](https://discourse.nixos.org/t/difference-between-fetchgit-and-fetchgit/3619/1 "2019-08-05T12:42:22Z")

</div>

There are two functions for fetching from a generic git repository, `fetchgit` from `nixpkgs` and `fetchGit` which is a built-in function. What is their difference and is one to be preferred over the other?

---

<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: [August 5, 2019, 7:11pm UTC](https://discourse.nixos.org/t/difference-between-fetchgit-and-fetchgit/3619/2 "2019-08-05T19:11:57Z")

</div>

`builtins.fetchGit` was added in 2.0, and from the release notes:

> `builtins.fetchGit` allows Git repositories to be fetched at evaluation time. Thus it differs from the `fetchgit` function in Nixpkgs, which fetches at build time and cannot be used to fetch Nix expressions during evaluation.

---

<div class="post-metadata">

### Author: ![ilikeavocadoes](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/i/848f3c/32.png) [@ilikeavocadoes](https://discourse.nixos.org/u/ilikeavocadoes)
#### Post date: [August 5, 2019, 7:16pm UTC](https://discourse.nixos.org/t/difference-between-fetchgit-and-fetchgit/3619/3 "2019-08-05T19:16:27Z")

</div>

What’s the difference between build time and evaluation time in nix?

---

<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: [August 5, 2019, 8:05pm UTC](https://discourse.nixos.org/t/difference-between-fetchgit-and-fetchgit/3619/4 "2019-08-05T20:05:57Z")

</div>

`nix-instantiate` evaluates a Nix expression to produce a derivation. `nix-store --realise` will then build a derivation and produce the outputs. `nix-build` is essentially a wrapper around both.

You can also see this in `nix repl` where running `builtins.fetchGit` immediately fetches the repo and gives you info about it:

```auto
nix-repl> builtins.fetchGit { url = "https://github.com/NixOS/patchelf"; }
{ outPath = "/nix/store/hl1kqvll4km3p8ia9vlgggxjwvsyg6w1-source"; rev = "1bc54f0f74ae3a307aef68e2923661dbf4e1cd76"; revCount = 335; shortRev = "1bc54f0"; }

```

whereas `fetchgit` evaluates to a derivation whose builder is a script that uses `git` to check out the repo, so if you evaluate it in `nix repl` all you get is a derivation, and you have to actually build it before you get the git repo.

---

<div class="post-metadata">

### Author: ![zimbatm](https://discourse.nixos.org/user_avatar/discourse.nixos.org/zimbatm/32/4_2.png) [@zimbatm](https://discourse.nixos.org/u/zimbatm)
#### Post date: [August 6, 2019, 9:09am UTC](https://discourse.nixos.org/t/difference-between-fetchgit-and-fetchgit/3619/5 "2019-08-06T09:09:02Z")

</div>

I find it helpful to think of the nix client and nix daemon to be separate things.

1. The nix client is responsible for evaluating the nix expression language and produces build recipes (.drv files) and fixed-output files. The fixed-output files are when file paths are being used for example. Or any of the builtins.fetch\* methods. It then talks to the nix daemon to add those to the store and build them.

2. The nix daemon is responsible for the whole `/nix` folder. It has a RPC protocol to receive fixed-output files and .drv files. It can be asked to build derivations… Some of those derivations have a determined fixed output and are also implemented as fetchers.

Even in single-user mode, the nix client and daemon are just in the same process.

---

<div class="post-metadata">

### Author: ![CMCDragonkai](https://discourse.nixos.org/user_avatar/discourse.nixos.org/cmcdragonkai/32/1934_2.png) [@CMCDragonkai](https://discourse.nixos.org/u/CMCDragonkai)
#### Post date: [December 16, 2019, 2:07am UTC](https://discourse.nixos.org/t/difference-between-fetchgit-and-fetchgit/3619/6 "2019-12-16T02:07:47Z")

</div>

I’m thinking that the difference between the fetchGits can be useful depending on whether you’re in a dev environment or staging environment.

Suppose you’re trying to setup CI/CD system using Nix for your organization. Then the CI runners need to use Nix to fetch private source dependencies from your Gitlab server. It one uses SSH keys to do this, then it might be nice to bake in SSH keys into the Nix runner image, but also prevent the user who submits the job from acquiring those keys. This means using instead `pkgs.fetchgit` or `pkgs.fetchgitPrivate`.

---

<div class="post-metadata">

### Author: ![jonringer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jonringer/32/1348_2.png) [@jonringer](https://discourse.nixos.org/u/jonringer)
#### Post date: [December 16, 2019, 4:10am UTC](https://discourse.nixos.org/t/difference-between-fetchgit-and-fetchgit/3619/7 "2019-12-16T04:10:00Z")

</div>

fetchgitPrivate has been removed in master, builtins.fetchGit as it is able to use native auth methods to pull down sources, thus making fetchgitPrivate obsolete.

---

<div class="post-metadata">

### Author: ![n0099](https://discourse.nixos.org/user_avatar/discourse.nixos.org/n0099/32/35787_2.png) [@n0099](https://discourse.nixos.org/u/n0099)
#### Post date: [July 28, 2026, 1:13pm UTC](https://discourse.nixos.org/t/difference-between-fetchgit-and-fetchgit/3619/8 "2026-07-28T13:13:17Z")

</div>

From [nixpkgs manual](https://github.com/NixOS/nixpkgs/blob/7fcb97de7c655e1809f8bb05f3d0f61bfa1c8abc/doc/build-helpers/fetchers.chapter.md?plain=1#L6-L24):

> [@](#):
>
> Nix provides built-in fetchers such as [`fetchTarball`](https://nixos.org/manual/nix/stable/language/builtins.html#builtins-fetchTarball).  
> Nixpkgs provides its own fetchers, which work differently:
> 
> - A built-in fetcher will download and cache files at evaluation time and produce a [store path](https://nixos.org/manual/nix/stable/glossary#gloss-store-path).  
> A Nixpkgs fetcher will create a ([fixed-output](https://nixos.org/manual/nix/stable/glossary#gloss-fixed-output-derivation)) [derivation](https://nixos.org/manual/nix/stable/glossary#gloss-derivation), and files are downloaded at build time.
> - Built-in fetchers will invalidate their cache after [`tarball-ttl`](https://nixos.org/manual/nix/stable/command-ref/conf-file#conf-tarball-ttl) expires, and will require network activity to check if the cache entry is up to date.  
> Nixpkgs fetchers only re-download if the specified hash changes or the store object is not available.
> - Built-in fetchers do not use [substituters](https://nixos.org/manual/nix/stable/command-ref/conf-file#conf-substituters).  
> Derivations produced by Nixpkgs fetchers will use any configured binary cache transparently.
> 
> This significantly reduces the time needed to evaluate Nixpkgs, and allows [Hydra](https://nixos.org/hydra) to retain and re-distribute sources used by Nixpkgs in the [public binary cache](https://cache.nixos.org).  
> For these reasons, Nix’s built-in fetchers are not allowed in Nixpkgs.
> 
> The following table summarises the differences:
> 
> | Fetchers | Download | Output | Cache | Re-download when |
> | --- | --- | --- | --- | --- |
> | `builtins.fetch*` | evaluation time | store path | `/nix/store`, `~/.cache/nix` | `tarball-ttl` expires, cache miss in `~/.cache/nix`, output store object not in local store |
> | `pkgs.fetch*` | build time | derivation | `/nix/store`, substituters | output store object not available |
