Repository template for a Rust project that pulls in the rust compiler (and
cargo etc.) via nix. The shell.nix
file provides an environment containing
rustc
and cargo
, as well as the libstd source code for facilitating the use
of rust-analyzer.
Rust-Analyzer itself is not provided via the nix environment, as the official Rust-Analyzer plugin for VS Code already takes care of downloading the latest version (and even patches the binary for NixOS).
Simply spawn a nix shell by running nix-shell
in this directory. Inside that
shell, rustc
and some convenience tools are available. Instead of running
nix-shell
manually, direnv can improve usability. A
suitable .envrc
is included.
For use with VS Code it is important to start VS Code from within the
nix-shell
session by running code .
. That way, it will capture the
environment of the nix shell. Otherwise, it won't be able to find rustc and the
libstd sources.
The nix dependencies are managed using niv.
Niv is provided via the shell.nix
environment. In order to get the latest
snapshot, just run niv update
inside the nix shell.
Currently, the master branch of
mozilla/nixpkgs-mozilla seems to be broken in that it
cannot build the rust-src
derivation. Therefore, the nixpkgs-mozilla
reference in
nix/sources.json
currently points to a fork of that repository with a hotfix
applied that was taken from
mozilla/nixpkgs-mozilla#304 (comment) and seems to fix the
build.