Cannot replace fetchGit with fetchFromGitHub

The nixos-hardware readme gives an example how to import it using builtins.fetchGit: nixos-hardware/README.md at 58b52b0dd191af70f538c707c66c682331cfdffc · NixOS/nixos-hardware · GitHub - "${builtins.fetchGit { url = "https://github.com/NixOS/nixos-hardware.git"; }}/lenovo/thinkpad/x220"

If I use pkgs.fetchFromGitHub instead, I run into an error when executing nixos-rebuild switch:

error:
       … while evaluating the attribute 'config'

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          323|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: infinite recursion encountered

Who has an idea why I cannot use those interchangeably?

Ah, that’ll happen if you try to use anything from Nixpkgs in code that defines what imports you’re using. An overlay might redefine fetchFromGitHub, and while nixos-hardware doesn’t have any such overlays there’s no way to know that before loading the imports, so loading the imports can’t depend on fetchFromGitHub.

builtins, of course, doesn’t have that problem.

1 Like

Sounds reasonable, thanks! :wink: