Skip to content

Rust

The languages.rust module provides comprehensive support for Rust development, offering flexible toolchain management through two distinct approaches.

Getting started

Enable Rust support in your devenv.nix:

{
  languages.rust.enable = true;
}

This will provide a complete Rust development environment with rustc, cargo, clippy, rustfmt, and rust-analyzer.

Toolchain management

devenv supports two approaches for managing Rust toolchains:

1. nixpkgs channel (default)

The nixpkgs channel is easy to set up and uses the Rust version currently available in your nixpkgs revision. However, it's limited to the version in nixpkgs.

{
  languages.rust = {
    enable = true;
    channel = "nixpkgs"; # default
  };
}

2. rust-overlay channels

For more control over versions and features, use the stable, beta, or nightly channels powered by rust-overlay:

  • ✅ Rustup-like channel selection
  • ✅ Access to any Rust version
  • ✅ Support for cross-compilation targets
{
  languages.rust = {
    enable = true;
    channel = "stable";
    version = "1.81.0"; # or "latest"
  };
}

Examples

Basic setup with latest stable

{
  languages.rust = {
    enable = true;
    channel = "stable";
  };
}

Nightly Rust with extra components

{
  languages.rust = {
    enable = true;
    channel = "nightly";
    components = [ "rustc" "cargo" "clippy" "rustfmt" "rust-analyzer" "miri" ];
  };
}

Cross-compilation setup

{
  languages.rust = {
    enable = true;
    channel = "stable";
    targets = [ "wasm32-unknown-unknown" "aarch64-unknown-linux-gnu" ];
  };
}

Minimal installation

{
  languages.rust = {
    enable = true;
    channel = "stable";
    components = [ "rustc" "cargo" "rust-std" ];
  };
}

Integration with other tools

Git hooks

Rust tools integrate seamlessly with git hooks:

{
  languages.rust.enable = true;

  git-hooks.hooks = {
    rustfmt.enable = true;
    clippy.enable = true;
  };
}

Options

languages.rust.enable

Whether to enable tools for Rust development.

Type: boolean

Default: false

Example: true

languages.rust.channel

The rustup toolchain to install.

Type: one of “nixpkgs”, “stable”, “beta”, “nightly”

Default: "nixpkgs"

languages.rust.components

List of Rustup components to install. Defaults to those available in nixpkgs.

Type: list of string

Default: [ "rustc" "cargo" "clippy" "rustfmt" "rust-analyzer" ]

languages.rust.mold.enable

Use mold as the linker.

mold is a faster drop-in replacement for existing Unix linkers. It is several times quicker than the LLVM lld linker.

Type: boolean

Default: false

languages.rust.rustflags

Extra flags to pass to the Rust compiler.

Type: string

Default: ""

languages.rust.targets

List of extra targets to install. Defaults to only the native target.

Type: list of string

Default: [ ]

languages.rust.toolchain

Rust component packages. May optionally define additional components, for example miri.

Type: attribute set of package

Default: nixpkgs

languages.rust.toolchain.cargo

cargo package

Type: null or package

Default: pkgs.cargo

languages.rust.toolchain.clippy

clippy package

Type: null or package

Default: pkgs.clippy

languages.rust.toolchain.rust-analyzer

rust-analyzer package

Type: null or package

Default: pkgs.rust-analyzer

languages.rust.toolchain.rustc

rustc package

Type: null or package

Default: pkgs.rustc

languages.rust.toolchain.rustfmt

rustfmt package

Type: null or package

Default: pkgs.rustfmt

languages.rust.toolchainPackage

The aggregated toolchain package, which includes the configured components and targets. This is automatically set based on the channel and components configuration.

Type: package

languages.rust.version

Which version of rust to use, this value could be latest,1.81.0, 2021-01-01. Only works when languages.rust.channel is NOT nixpkgs.

Type: string

Default: "latest"