This change allows the caller to replace the fetchTarball used for fetching the inputs of the flake with pkgs.fetchzip, which works as a drop-in replacement. The difference is that builtins.fetchTarball does the fetching at Nix evaluation time, while pkgs.fetchzip does the fetching at build time. The distinction becomes crucial when one attempts to build a flake output inside a recursive-nix derivation. A vanilla nix build ${someFlake} or a nix-build default.nix using the current flake-compat will fail inside a recursive Nix when fetchTarball attempts to download the tarball, but the following derivation (using the flake-compat from this PR) will successfully build (on a system with recursive-nix):
In the above Nix expression, if you remove the fetchTarball argument from line 11, then the build will fail with:
error: unable to download 'https://api.github.com/repos/NixOS/nixpkgs/tarball/970a59bd19eff3752ce552935687100c46e820a5': Couldn't resolve host name (6)
Building a flake recursively like this allows us to hide its evaluation inside a derivation, which can be a world of difference in some cases (see this discussion thread I've opened a few months ago where I've explained in detail how bad this can get).
This approach essentially allows us to get a kind of nix flake output evaluation caching as part of a larger Nix evaluation.
This change allows the caller to replace the
fetchTarball
used for fetching the inputs of the flake withpkgs.fetchzip
, which works as a drop-in replacement. The difference is thatbuiltins.fetchTarball
does the fetching at Nix evaluation time, whilepkgs.fetchzip
does the fetching at build time. The distinction becomes crucial when one attempts to build a flake output inside arecursive-nix
derivation. A vanillanix build ${someFlake}
or anix-build default.nix
using the currentflake-compat
will fail inside a recursive Nix whenfetchTarball
attempts to download the tarball, but the following derivation (using theflake-compat
from this PR) will successfully build (on a system withrecursive-nix
):In the above Nix expression, if you remove the
fetchTarball
argument from line 11, then the build will fail with:Building a flake recursively like this allows us to hide its evaluation inside a derivation, which can be a world of difference in some cases (see this discussion thread I've opened a few months ago where I've explained in detail how bad this can get).
This approach essentially allows us to get a kind of nix flake output evaluation caching as part of a larger Nix evaluation.