Skip to content

Commit

Permalink
Merge pull request #82 from DeterminateSystems/rust-analyzer-issue
Browse files Browse the repository at this point in the history
Make Rust Analyzer flakes more granular
  • Loading branch information
lucperkins authored Nov 13, 2023
2 parents 8367544 + aa897be commit 189583c
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/cli/cmd/init/handlers/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ impl Handler for Rust {
.push(String::from("rust-overlay.overlays.default"));

let rust_toolchain_func = String::from(if project.has_file("rust-toolchain") {
"final.rust-bin.fromRustupToolchainFile ./rust-toolchain"
"(final.rust-bin.fromRustupToolchainFile ./rust-toolchain)"
} else if project.has_file("rust-toolchain.toml") {
"final.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml"
"(final.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml)"
} else {
// TODO: make this more granular
"final.rust-bin.stable.latest.default"
});

flake
.overlay_attrs
.insert(String::from("rustToolchain"), rust_toolchain_func);

flake.dev_shell_packages.push(String::from("rustToolchain"));

// Add cargo-* tools
Expand All @@ -43,6 +39,25 @@ impl Handler for Rust {

if Prompt::bool("Would you like to add Rust Analyzer to the environment?") {
flake.dev_shell_packages.push(String::from("rust-analyzer"));

let rust_toolchain_func_with_override = format!(
"{}.override {{ extensions = [ \"rust-src\"]; }}",
rust_toolchain_func
);

flake.overlay_attrs.insert(
String::from("rustToolchain"),
rust_toolchain_func_with_override,
);

flake.env_vars.insert(
String::from("RUST_SRC_PATH"),
String::from("${pkgs.rustToolchain}/lib/rustlib/src/rust/library"),
);
} else {
flake
.overlay_attrs
.insert(String::from("rustToolchain"), rust_toolchain_func);
}

if Prompt::bool(
Expand Down

0 comments on commit 189583c

Please sign in to comment.