nix-community / crate2nix

rebuild only changed crates in CI with crate2nix and nix
https://nix-community.github.io/crate2nix/
Apache License 2.0
335 stars 82 forks source link

Installs `rustc` from nixpkgs when already installed #349

Closed pseudoparenchymatous closed 1 month ago

pseudoparenchymatous commented 1 month ago

I am using fenix as my rust overlay; installed it in my dev-shell using nativeBuildInputs. But when I run nix build, it reinstalls the toolchain (i.e. rustc) from nixpkgs.

And if I remove nixpkgs from my inputs, nix build behaves as expected and builds the crate.

image

pseudoparenchymatous commented 1 month ago

Disable nixpkgs in inputs

image

nix build/nix run without problem

image

pseudoparenchymatous commented 1 month ago

Fixed it by overlaying directly the rustc and cargo packages from nixpkgs

pseudoparenchymatous commented 1 month ago

Nope. Overlaying rustc and cargo directly doesn't seem to be the correct way. It breaks other packages from nixpkgs that may rely on nixpkgs' derivation of rustc/cargo.

So what's the right way of telling crate2nix to use/download/install rustc/cargo from another source other than nixpkgs?

pseudoparenchymatous commented 1 month ago

Fixed it with

let
  minimal-toolchain = fenix.packages.${system}.stable.minimalToolchain;
  cargoNix = pkgs.callPackage ./Cargo.nix {
    buildRustCrateForPkgs = pkgs: pkgs.buildRustCrate.override {
      rustc = minimal-toolchain;
      cargo = minimal-toolchain;      
    };
  };
in packages.default = cargoNix.rootCrate.build;