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

Support for +<toolchain> rustup feature #110

Open
eureka-cpu opened this issue Jun 21, 2023 · 7 comments
Open

Support for +<toolchain> rustup feature #110

eureka-cpu opened this issue Jun 21, 2023 · 7 comments

Comments

@eureka-cpu
Copy link

Adding this for posterity in case someone else finds themselves here.

My particular use case was for nightly formatting like so: cargo +nightly fmt in a script that formats all files.

I was able to work around this by installing the nightly toolchain and changing the above to rustup run nightly cargo fmt, then adding the unstable_features = true option to the rustfmt.toml.

To quote @figsoda on the topic:

+<toolchain> is a rustup feature and fenix doesn’t currently support it. You should be able to just remove the +nightly argument and the same command should work. You can make a wrapper for cargo (and possibly other components) that skips the first argument if it starts with +. I’m not sure that this will ever be implemented within fenix, if it gets implemented it will probably be a separate tool that wraps nix and uses fenix under the hood.

@dpc
Copy link

dpc commented Sep 28, 2023

Can you explain more why and where exactly do you need it?

Personally I always use nightly rustfmt with stable toolchain. In my own project I use combine, but for ad-hoc use I have a script:

> cat ~/bin/nix-rust-flake-shell
#!/usr/bin/env bash

nixpkgs=github:NixOS/nixpkgs/nixos-23.05

exec nix shell github:nix-community/fenix#complete.rustfmt github:nix-community/fenix#stable.rustc github:nix-community/fenix#stable.cargo  $nixpkgs#rust-analyzer $nixpkgs#pkg-config $nixpkgs#openssl
19:36:02 ~/lab/redb  master:origin/master [✘!?] is 📦 v1.1.0 via 🐍 v3.10.12 🦀 
> nix-rust-flake-shell
19:36:06 ~/lab/redb  master:origin/master [✘!?] is 📦 v1.1.0 via 🐍 v3.10.12 🦀v1.72.1 
> rustfmt --version
rustfmt 1.6.0-nightly (5ae769f 2023-09-26)
19:36:09 ~/lab/redb  master:origin/master [✘!?] is 📦 v1.1.0 via 🐍 v3.10.12 🦀v1.72.1 
> rustc --version
rustc 1.72.1 (d5c2e9c34 2023-09-13)

@DanGould
Copy link

DanGould commented Jan 9, 2024

I've use this +<toolchain> feature to test building against a specific MSRV in the past. @dpc do you suggest running a new nix shell with a specific version for this purpose?

@eureka-cpu
Copy link
Author

There are some cargo features and tools that can't be used without the +<toolchain> feature, but I've sort of come to accept that fenix likely won't support this so I've just used nix-shell -p rustup for the times I've needed to use those features. It's not ideal, but it works.

@dpc
Copy link

dpc commented Jan 10, 2024

+toolchain is a rustup binary wrapper functionality, and can't be done without it.

With fenix one can just instantiate multiple fenix instances with different toolchains (e.g. using toolchainOf). For more than just a one-off operation, this often requires wrapping a bunch of things in a function to parametrize it over the exact fenix toolchain.

I should add support for it to Flakebox ... 🤔

@eureka-cpu
Copy link
Author

I'm happy to see this closed, but glad the conversation was had if not just for posterity. Thanks for the recommendation!

@tmillr
Copy link

tmillr commented Mar 17, 2024

I'm having issues with cargo fmt as well and I think it might be related to this. When I invoke rustfmt directly, I (correctly) get the nightly version, but cargo fmt uses stable version of rustfmt. How is this even possible, and what is the fix/workaround? Is it only possible to use rustfmt nightly (for cargo fmt) via rustup?

@figsoda

You should be able to just remove the +nightly argument and the same command should work.

This doesn't appear to be the case, unless I'm doing something wrong.

@MathisWellmann
Copy link

MathisWellmann commented Apr 4, 2024

I'm having issues with cargo fmt as well and I think it might be related to this. When I invoke rustfmt directly, I (correctly) get the nightly version, but cargo fmt uses stable version of rustfmt. How is this even possible, and what is the fix/workaround? Is it only possible to use rustfmt nightly (for cargo fmt) via rustup?

@tmillr You can use lib.hiPrio to override rustfmt. Here is a quick snippet that I use in my flake.nix:

flake-utils.lib.eachDefaultSystem (
      system: let
        <SNIP>
        rust = (
          pkgs.rust-bin.stable."1.76.0".default.override {
            extensions = [
              "rust-src"
              "rust-analyzer"
              "clippy"
            ];
            targets = ["x86_64-unknown-linux-gnu"];
          }
        );
      in
        with pkgs; {
          devShells.default = mkShell {
            buildInputs = [
              # We use the nightly formatter which is executed when running `cargo fmt`, without `+nightly` flag
              # which is a rustup binary wrapper functionality, which we don't use.
              (lib.hiPrio rust-bin.nightly."2024-04-01".rustfmt)
              rust
            ];
          };
        }
    );

With this you get the nightly version when you invoke it regularly like this:

$ cargo fmt --version
rustfmt 1.7.0-nightly (8058136 2024-03-31)

The full snippet can be found in trade_aggregation-rs.
Actually I'm using the rust-overlay but I imagine it should work the same for fenix as well. Correct me if I'm wrong

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

No branches or pull requests

5 participants