crate2nix icon indicating copy to clipboard operation
crate2nix copied to clipboard

crate2nix flake template: nixpkgs overlay causes infinite recursion in rust-overlay

Open reivilibre opened this issue 4 months ago • 0 comments

I think I have hit https://github.com/oxalica/rust-overlay/issues/198 whilst using the crate2nix flake template.

To reproduce:

  • init the crate2nix flake template according to instructions: nix flake init --template github:nix-community/crate2nix
  • update rust-overlay to get a later rust version with nix flake update rust-overlay
  • try to build: nix build .#rust-toolchain-versions

This gives the error:

error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:37:12:
           36|
           37|   strict = derivationStrict drvAttrs;
             |            ^
           38|

       … while evaluating derivation 'rust-toolchain-versions'
         whose name attribute is located at /nix/store/7b7m3p9gc9da6cd7wgyabs3wg1832j0v-source/pkgs/stdenv/generic/make-derivation.nix:348:7

       … while evaluating attribute 'text' of derivation 'rust-toolchain-versions'
         at /nix/store/7b7m3p9gc9da6cd7wgyabs3wg1832j0v-source/pkgs/build-support/trivial-builders/default.nix:148:17:
          147|     runCommand name
          148|       { inherit text executable checkPhase allowSubstitutes preferLocalBuild;
             |                 ^
          149|         passAsFile = [ "text" ];

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

       error: infinite recursion encountered
       at <nix/derivation-internal.nix>:50:7:
           49|     value = commonAttrs // {
           50|       outPath = builtins.getAttr outputName strict;
             |       ^
           51|       drvPath = strict.drvPath;

Looking at the source of the template, it looks like it is configuring nixpkgs to replace the rust toolchain with the one from rust-overlay:

https://github.com/nix-community/crate2nix/blob/be31feae9a82c225c0fd1bdf978565dc452a483a/templates/flake-binary/nix/rust-overlay/flake-module.nix#L5-L12

In a comment on the rust-overlay issue tracker it's apparently not recommended to do this unless you know what you are doing. I'm not sure what caveats are had in mind but it seems like this is at least responsible for this issue.

reivilibre avatar Nov 24 '25 17:11 reivilibre