Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using stable channel with rustfmt from nightly #136

Closed
DanConwayDev opened this issue Sep 11, 2023 · 8 comments
Closed

using stable channel with rustfmt from nightly #136

DanConwayDev opened this issue Sep 11, 2023 · 8 comments
Labels
question Further information is requested

Comments

@DanConwayDev
Copy link

DanConwayDev commented Sep 11, 2023

Does rust-overlay enable using rustfmt from nightly whilst otherwise using the stable toolchain?

With rustup both toolchains can be installed and nightly can be targeted by running cargo +nightly fmt.

#56 (comment) alludes to merging toolchains but I am not clear how this would be achieved.

Thanks for your efforts in creating and maintaining rust-overlay :)

@oxalica
Copy link
Owner

oxalica commented Sep 11, 2023

You can pick one component from nightly toolchain and use lib.hiPrio on it to override others.

[
  (lib.hiPrio rust-bin.nightly."2023-09-01".rustfmt)
  (rust-bin.stable.latest.default.override { /* default toolchain */ })
]

@oxalica oxalica added the question Further information is requested label Sep 11, 2023
@oxalica oxalica closed this as completed Sep 11, 2023
@spikespaz
Copy link

I have the same question and find myself unsatisfied with the answer.

      devShells = eachSystem (system:
        let pkgs = pkgsFor.${system};
        in {
          default = pkgs.mkShell {
            strictDeps = true;
            packages = with pkgs; [
              rust-bin.stable.latest.default.override
              (lib.hiPrio (rust-bin.selectLatestNightlyWith (toolchain:
                toolchain.minimal.override { extensions = [ "rustfmt" ]; })))
              pkg-config
              openssl
            ];
          };
        });

Obviously, that derivation would also overwrite rustc, cargo, and rust-std from stable with the nightly version.

I would like to stay up-to-date with the latest available nightly after every nix flake lock --update-input rust-overlay, and do not wish to specify a nightly release date.

@spikespaz
Copy link

spikespaz commented Sep 12, 2023

I don't like what I ended up with because, as you said, it is possible that one of these components doesn't build with the latest nightly.

devShells = eachSystem (system:
  let pkgs = pkgsFor.${system};
  in {
    default = pkgs.mkShell {
      strictDeps = true;
      packages = with pkgs; [
        (rust-bin.stable.latest.minimal.override {
          extensions = [ "rust-docs" ];
        })
        (lib.hiPrio rust-bin.nightly.latest.clippy)
        (lib.hiPrio rust-bin.nightly.latest.rustfmt)
        (lib.hiPrio rust-bin.nightly.latest.rust-analyzer)
        pkg-config
        openssl
      ];
    };
  });

I'd like to see something like this:

(rust-bin.selectLatestNightlyWith (toolchain:
  toolchain.minimal.override { extensions = [ "rustfmt" ];
})).extensions.rustfmt

@DanConwayDev
Copy link
Author

Thanks @oxalica. I have this working.

Like @spikespaz, I'd prefer not to pin a specific version of nightly and take advantage of selectLatestNightlyWith but that is icing on the cake.

@spikespaz
Copy link

spikespaz commented Sep 13, 2023

When using rust-analyzer from nightly.latest, I see errors like:

error[E0463]: can't find crate for `std`
 --> src/config/mod.rs:3:5
  |
3 | use std::collections::HashMap;
  |     ^^^ can't find crate

and

error[E0514]: found crate `serde` compiled by an incompatible version of rustc
 --> src/config/mod.rs:6:5
  |
6 | use serde::{Deserialize, Serialize};
  |     ^^^^^
  |
  = note: the following crate versions were found:
          crate `serde` compiled by rustc 1.72.0 (5680fa18f 2023-08-23): /home/jacob/Documents/linux-desktop/hyprland-workspace-profiles/target/debug/deps/libserde-cf278766bb3cc9aa.rmeta
  = help: please recompile that crate using this compiler (rustc 1.74.0-nightly (030e4d382 2023-09-10)) (consider running `cargo clean` first)

@spikespaz
Copy link

spikespaz commented Sep 13, 2023

Trying to handle nightly more correctly, attempted this:

devShells = eachSystem (system:
  let pkgs = pkgsFor.${system};
  in {
    default = pkgs.mkShell {
      strictDeps = true;
      packages = with pkgs; [
        (lib.hiPrio (rust-bin.stable.latest.minimal.override {
          extensions = [ "rust-docs" "rust-analyzer" ];
        }))
        (rust-bin.selectLatestNightlyWith (toolchain:
          toolchain.minimal.override {
            extensions = [ "clippy" "rustfmt" ];
          }))

        pkg-config
        openssl
      ];
    };
  });

Same problem though.

@spikespaz
Copy link

Using stable clippy, and nightly rustfmt and rust-analyzer works. Sticking with my last attempt, but switched extensions around slightly.

@sveitser
Copy link

I'd like to see something like this:

(rust-bin.selectLatestNightlyWith (toolchain:
  toolchain.minimal.override { extensions = [ "rustfmt" ];
})).extensions.rustfmt

@spikespaz There is passthru.availableComponents that seems to accomplish this, not sure if it's a good idea to use that though.

nightlyToolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal.override {
  extensions = [ "rustfmt" ];
});
...
buildInputs = [
  nightlyToolchain.passthru.availableComponents.rustfmt
  ...
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants