Centameta
← Back to Blog

Essential Nix commands for Rust projects

July 06, 2026

Nix gives you reproducible Rust toolchains without polluting your system. The modern CLI splits responsibilities into four commands you will use repeatedly: nix develop, nix shell, nix run, and nix build.

Four commands, four intents: develop, consume, execute, package.

Why this matters for Rust

Nix replaces ad-hoc global tooling with per-project environments. Each project declares its toolchain in a flake or shell.nix, and Nix materializes it on demand.

nix develop: the project workspace

nix develop starts an interactive shell with the dependencies your project expects. It does not run your build automatically; it gives you the environment so you can run your own commands.

# Enter the default dev shell
nix develop

# Or enter a named shell
nix develop .#rust

Inside the shell, you can run:

cargo build
cargo clippy
cargo test

nix shell: the one-off tool

nix shell is for consuming tools without installing them globally.

# Run a single tool without global install
nix shell nixpkgs#cargo-watch
cargo-watch -x test

# Use a specific version
nix shell nixpkgs#cargo
cargo --version

nix run: execute without entering

nix run resolves and executes in one step.

# Run from nixpkgs
nix run nixpkgs#cargo-audit -- audit

# Run flake app outputs
nix run .
nix run .#my-cli -- --help

nix build: produce the artifact

nix build compiles and stores deterministic outputs in the Nix store.

# Build default package
nix build

# Build named package
nix build .#my-app

# Inspect linked result
ls -l ./result
./result/bin/my-app --version

The command matrix

IntentCommandStops before buildGives binaryUse case
Write or debugnix developYesNoDependency-heavy Rust work
Use a toolnix shellYesYesAd-hoc binaries
Run and exitnix runNoNoOne-shot commands
Compile artifactnix buildNoYesReproducible outputs

Practical Rust workflow

# 1) Enter dev environment
nix develop

# 2) Build and test
cargo check --all-targets
cargo test
cargo build --release

# 3) Build package output
exit
nix build .#my-app

# 4) Run packaged output
nix run .#my-app
Core lesson: nix develop writes software, nix shell provides tools, nix run executes, and nix build ships.