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 rustToolchain variable for creating workspace #345

Open
JohnCarterGonzalez opened this issue Feb 13, 2024 · 2 comments
Open

using rustToolchain variable for creating workspace #345

JohnCarterGonzalez opened this issue Feb 13, 2024 · 2 comments

Comments

@JohnCarterGonzalez
Copy link

In the example docs for hello-world the rust workspace is built using:

# the flake.nix file is spliced here for brevity...
# create the workspace & dependencies package set
rustPkgs = pkgs.rustBuilder.makePackageSet {
  rustVersion = "1.75.0";
  packageFun = import ./Cargo.nix;
};
# rest of flake...

I usually create my development environments through a single rustToolchain file like so:

# again the flake is spliced for brevity...
# 👇 note that it refers to the path ./rust-toolchain.toml
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
in
with pkgs;
{
  devShells.default = mkShell {
    buildInputs = [
     rustToolchain
    ];
};
# rest of flake.nix....

Not saying this is the best approach, I am just curious if something like this is possible in the build dev-env section for cargo2nix? Thanks for your time.

@JohnCarterGonzalez
Copy link
Author

JohnCarterGonzalez commented Feb 13, 2024

an example of what I mean would be like:

rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
rustPkgs = pkgs.rustBuilder.makePackageSet {
  rustupToolchain = rustupToolchain; # not sure what the declaring variable would be here
  packageFun = import ./Cargo.nix;
  # ...

and the rust-toolchain.toml would look like:

[toolchain]
channel = "1.75"
profile = "minimal"
components = [ "rustfmt", "clippy" ]
targets = [ "x86_64-apple-darwin", "aarch64-apple-darwin", "wasm32-wasi" ]

the dev-env would be built using the toml file and the cargo2nix would build the bin rust pkg. I hope the example makes sense!

@psionic-k
Copy link
Member

The workspace shell attribute is an augmentation of vanila mkShell. You can put arbitrary things in as needed.

IIRC NIx has some toml reading tools. If you translate that to a toolchain expression, you can read a rust-toolchain.toml like in your example.

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

2 participants