Skip to content

Build fails when using rust-overlay due to some dependencies being built with Nixpkgs Rust when cross-compiling #359

Closed
@drakon64

Description

@drakon64

I have a simple derivation using crate2nix:

{
  pkgs,
  crate2nix,
  system,
  src,
  ...
}:
let
  rustToolchain = pkgs.rust-bin.stable."1.80.1".default;

  buildRustCrateForPkgs =
    pkgs:
    pkgs.buildRustCrate.override {
      rustc = rustToolchain;
      cargo = rustToolchain;
    };

  generatedCargoNix = crate2nix.tools.${system}.generatedCargoNix {
    name = "package";
    inherit src;
  };

  cargoNix = import generatedCargoNix {
    inherit pkgs buildRustCrateForPkgs;
  };
in
cargoNix.rootCrate.build

When I try to build this, I get this error:

error[E0514]: found crate `derive_builder_macro` compiled by an incompatible version of rustc
   --> src/lib.rs:718:1
    |
718 | extern crate derive_builder_macro;
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: the following crate versions were found:
            crate `derive_builder_macro` compiled by rustc 1.80.1 (3f5fd8dd4 2024-08-06) (built from a source tarball): /nix/store/ay24n13hpxymp9wvrw08a0qh5fwzkhlx-rust_derive_bui>
    = help: please recompile that crate using this compiler (rustc 1.80.1 (3f5fd8dd4 2024-08-06)) (consider running `cargo clean` first)

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0514`.

If I downgrade the Rust overlay to 1.80.0, I get the same error but with 'this' compiler correctly appearing as 1.80.0.

It seems like crate2nix is still building some of the dependencies with the Nixpkgs version of Rust.

In my Flake, pkgs is defined as follows:

pkgs = import nixpkgs {
  inherit system;

  overlays = [ (import rust-overlay) ];

  crossSystem = {
    config = "x86_64-unknown-linux-musl";
  };
};

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