Rust: Difference between revisions
imported>Torhovland Added crane and dream2nix. |
imported>Torhovland Cleaned up duplicate mkShell samples. |
||
Line 23: | Line 23: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
== Installation via rustup == | == Installation via rustup == | ||
Line 147: | Line 122: | ||
}) | }) | ||
]; | ]; | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Line 258: | Line 207: | ||
buildInputs = with pkgs; [ rustfmt clippy ]; | buildInputs = with pkgs; [ rustfmt clippy ]; | ||
# Certain Rust tools won't work without this | |||
# This can also be fixed by using oxalica/rust-overlay and specifying the rust-src extension | |||
# See https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570/3?u=samuela. for more details. | |||
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; | RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
This will have the stable Rust compiler + the official formatter and linter inside the ephemeral shell. It'll also set the RUST_SRC_PATH environment variable to point to the right location, which tools, such as rust-analyzer, require to be set. | This will have the stable Rust compiler + the official formatter and linter inside the ephemeral shell. It'll also set the RUST_SRC_PATH environment variable to point to the right location, which tools, such as rust-analyzer, require to be set. | ||
=== VSCode integration === | |||
The [https://marketplace.visualstudio.com/items?itemName=rust-lang.rust rust-lang.rust] and [https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer rust-lang.rust-analyzer] VSCode extensions offer Rust support. | |||
You can use the [https://marketplace.visualstudio.com/items?itemName=arrterian.nix-env-selector arrterian.nix-env-selector] extension to enable your nix-shell inside VSCode and have these settings picked up by other extensions. | |||
=== Neovim Completion === | |||
Racer completion can be configured using the following snippet: | |||
<syntaxHighlight lang="nix"> | |||
(neovim.override { | |||
configure = { | |||
customRC = '' | |||
if filereadable($HOME . "/.vimrc") | |||
source ~/.vimrc | |||
endif | |||
let $RUST_SRC_PATH = '${stdenv.mkDerivation { | |||
inherit (rustc) src; | |||
inherit (rustc.src) name; | |||
phases = ["unpackPhase" "installPhase"]; | |||
installPhase = ''cp -r library $out''; | |||
}}' | |||
''; | |||
packages.nixbundle.start = with vimPlugins; [ | |||
nvim-completion-manager | |||
nvim-cm-racer | |||
]; | |||
}; | |||
}) | |||
</syntaxHighlight> | |||
== FAQ == | == FAQ == |