oxalica / rust-overlay

Pure and reproducible nix overlay of binary distributed rust toolchains
MIT License
956 stars 56 forks source link

How to get cargo etc from a toolchain file? #151

Closed wmertens closed 10 months ago

wmertens commented 10 months ago

I tried using fromRustupToolchainFile for rust-bin, but cargo etc still use the latest nightly.

How can I make sure that all the tools use the same rust version from the toolchain file?

oxalica commented 10 months ago

I tried using fromRustupToolchainFile for rust-bin, but cargo etc still use the latest nightly.

Please paste the Nix code you are using, and how you enter the development environment for cargo.

wmertens commented 10 months ago

Here's my flake.nix:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
    rust-overlay.url = "github:oxalica/rust-overlay";
  };

  outputs = { self, rust-overlay, nixpkgs }:
    let
      b = builtins;
      devShell = system: _pkgs:
        let
          overlays = [ (import rust-overlay) ];
          pkgs = import nixpkgs {
            inherit system overlays;
          };
        in
        {
          default = pkgs.mkShell {
            nativeBuildInputs = with pkgs; [
              bashInteractive
              gitMinimal

              nodejs_20

              # Qwik optimizer deps
              cargo
              clippy
              wasm-pack
              ((rust-bin.fromRustupToolchainFile
                ./rust-toolchain).override {
                targets = [ "wasm32-unknown-unknown" ];
              })
            ];
          };
        };
    in
    {
      devShells = b.mapAttrs (devShell) nixpkgs.legacyPackages;
    };
}

As you can see I only get the rustc from the toolchain file, I can't figure out how to get the rest

oxalica commented 10 months ago
        nativeBuildInputs = with pkgs; [
          bashInteractive
          gitMinimal

          nodejs_20

          # Qwik optimizer deps
          cargo
          clippy
          wasm-pack
          ((rust-bin.fromRustupToolchainFile
            ./rust-toolchain).override {
            targets = [ "wasm32-unknown-unknown" ];
          })
        ];

You have cargo explicitly listed here, which is picked from pkgs and overrides the cargo from fromRustupToolchainFile. Please remove the cargo line.

wmertens commented 10 months ago

That did the trick thank you :pray::pray::pray: