Rust Rover
From NixOS Wiki
								(Redirected from NixOS Wiki:Rust Rover)
												
				RustRover with NixOS flakes
JetBrains RustRover is an IDE tailored for Rust development.  
On NixOS, rustup is difficult to work with, and in many cases with nix packages are slow to add new versions. For this reason its is easier to work with a flake in order to provide a reproducible toolchain (including rustc, cargo, rust-analyzer, clippy, rustfmt, and rust-src).  
This article describes a way to set up rust-rover, such that it works with supported versions of rust.
Prerequisites
- NixOS with flakes enabled
- Basic familiarity with flakes and nix develop
- A JetBrains account (RustRover requires a license, though free for some users)
Flake setup
The following flake defines a development shell with the Rust toolchain and common system dependencies:
{
  description = "Rust Rover environment";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    rust-overlay.url = "github:oxalica/rust-overlay";
    flake-utils = {
      url = "github:numtide/flake-utils";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
  outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [ (import rust-overlay) ];
        };
        rustToolchain = pkgs.rust-bin.stable."1.88.0".default.override {
          extensions = [ "rust-src" "clippy" "rustfmt" ];
        };
      in {
        devShell = pkgs.mkShell {
          nativeBuildInputs = with pkgs; [
            rustToolchain
          ];
          buildInputs = with pkgs; [
            openssl
            pkg-config
            rust-analyzer
            jetbrains.rust-rover
          ];
          shellHook = ''
            mkdir -p ~/.rust-rover/toolchain
            ln -sfn ${rustToolchain}/lib ~/.rust-rover/toolchain
            ln -sfn ${rustToolchain}/bin ~/.rust-rover/toolchain
            export RUST_SRC_PATH="$HOME/.rust-rover/toolchain/lib/rustlib/src/rust/library"
          '';
        };
      }
    );
}
Explanation
- rust-overlay: Provides reproducible Rust toolchains in Nix
- rustToolchain: Defines the Rust version and extensions (- rust-src,- clippy,- rustfmt)
- shellHook: Creates symlinks into- $HOMEso IDEs always see a stable path for- cargo,- rustc, and source libraries, even if the underlying Nix store path changes
- RUST_SRC_PATH: Needed by some tools (e.g., rust-analyzer) to find the standard library sources
Using with RustRover
1. Enter the dev shell:
nix develop
2. Launch RustRover from inside the shell:
rust-rover
3. In RustRover:
- Go to Settings → Rust
- Rust rover only supports full paths, so set the toolchain location to:
/home/<username>/.rust-rover/toolchain/bin/- Then set the standard library path to:
/home/<username>/.rust-rover/toolchain/lib/rustlib/src/rust/libraryNotes
- You do not need rustup, the overlay provides pinned, reproducible Rust toolchains
- Additional dependencies (OpenSSL, libGL, X11, etc.) can be added to buildInputsas required by your project
- The symlink provides rust rover stable paths it can use.