Replace nixpkgs fetchers with nix builtins fetchers?

Nix provides some builtins to fetch source code. It seems that we could use those instead of the nixpkgs fetchers.

Does it make sense to replace nixpkgs fetchers with the Nix fetchers?

It also seems that the builtin fetchers are doing the right thing:

$ nix-store -r $(nix-instantiate '<nixpkgs>' -A fetchgit --argstr url "" --argstr hash "sha256-MtVatZVsV+dtjdD4AC4bztrnDFas+WZYHzQMt41FwzU=" --argstr rev "refs/tags/2.13.2")

$ nix-store -r $(nix-instantiate '<nixpkgs>' -A fetchgit --argstr url "" --argstr hash "sha256-MtVatZVsV+dtjdD4AC4bztrnDFas+WZYHzQMt41FwzU=" --argstr rev "4935cf4d9b74405c753942197c9f328075793502")

$ nix-store -r $(nix-instantiate '<nixpkgs>' -A fetchzip --argstr url "" --argstr hash "sha256-MtVatZVsV+dtjdD4AC4bztrnDFas+WZYHzQMt41FwzU=")


$ nix eval --expr '(builtins.fetchGit { url= ""; ref="refs/tags/2.13.2"; allRefs=true; narHash="sha256-MtVatZVsV+dtjdD4AC4bztrnDFas+WZYHzQMt41FwzU=";}).outPath'

$ nix eval --expr '(builtins.fetchGit { url= ""; rev = "4935cf4d9b74405c753942197c9f328075793502"; allRefs=true; narHash="sha256-MtVatZVsV+dtjdD4AC4bztrnDFas+WZYHzQMt41FwzU=";}).outPath'

$ nix eval --expr '(builtins.fetchTarball {url=""; sha256="sha256-MtVatZVsV+dtjdD4AC4bztrnDFas+WZYHzQMt41FwzU=";})'

The hash is always the same. We get 3 different store paths with the nixpkgs fetchers, but with the builtin fetchers we get always the same store path.

Not saying we shouldn’t do that, but the main reason that we don’t use builtins fetchers is because they run at eval time and return paths instead of derivations, and therefore can’t be served as binary cache.

1 Like

You can also get the same store paths from the nixpkgs fetchers by adding --argstr name source.

1 Like

Built-in fetchers block the evaluator and return a valid path when it’s been downloaded.

Fixed-output derivation based fetchers (ie nixpkgs) return a string with context to represent the downloaded path, so that it doesn’t block the evaluator. This is why you can evaluate a package without having to wait for a thousand irrelevant source dependencies to download, one by one, sequentially.