Skip to content

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

@reivilibre

Description

@reivilibre

I think I have hit oxalica/rust-overlay#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:

(self: super: assert !(super ? rust-toolchain); rec {
rust-toolchain = super.rust-bin.fromRustupToolchainFile ../../rust-toolchain.toml;
# buildRustCrate/crate2nix depend on this.
rustc = rust-toolchain;
cargo = rust-toolchain;
})
];

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions