Rust¶
Configure a shell with development tools¶
Given a project named proj
with a pkgs/proj/default.nix
file, create a file shells/proj-shell/default.nix
that looks like this:
{
mkShell,
rustPlatform,
proj, # (1)!
# Add development tools here
rust-analyzer, # (2)!
clippy,
}:
mkShell {
inputsFrom = [
proj # (3)!
];
packages = [
rust-analyzer # (4)!
clippy
];
RUST_SRC_PATH = "${rustPlatform.rustLibSrc}"; # (5)!
}
- You must include the package as an input so that you can later extract the build inputs from it.
- Add any development tools you want as inputs. Here we use
rust-analyzer
andclippy
so that you can use these from your IDE in the flox environment. If you wanted to add other development tools like Cargo subcommands, you would add those here as well. Note the commas after each item! inputsFrom
will extract any necessary build inputs from the definition of the package so that you don't need to repeat them in this file.- Add the development tools that you listed in the inputs here. Note that you shouldn't add commas between items here.
- Set this environment variable so that
rust-analyzer
can provide type definitions, autocomplete, etc for items in the Rust standard library.
To enter the shell, use the [flox develop
][flox_develop] command and select proj-shell
:
You should now have access to development tools in your shell, and an editor launched from this shell should have access to rust-analyzer
and clippy
.