purr · git-hooks · rust · cargo · clippy · nix-flake
Nix flake template for Rust development — batteries-included dev shell, pre-commit guardrails, and reproducible builds via cargo + rustPlatform. Drop into direnv, start hacking.
Part of the develop-templates collection (nix flake init-ready).
nix flake init -t "github:nixcafe/develop-templates#rust" --refreshRegister an alias:
nix registry add beans "github:nixcafe/develop-templates"
nix flake init -t beans#rustTip: With cattery-modules,
beansis pre-registered.
gh repo create my-rust-project --template nixcafe/rust --clonedirenv allow
cargo build| Tool | Purpose |
|---|---|
cargo / rustc / rustLibSrc |
Rust toolchain via rustPlatform |
clippy |
Rust linter — catches common mistakes |
rustfmt |
Rust formatter — consistent code style |
pkg-config |
Build dependency discovery |
RUST_SRC_PATH |
LSP source path for rust-analyzer |
Override rustPlatform in develop/shells/default/default.nix:
# pin to a specific nightly
toolchain = pkgs.rust-bin.nightly.latest.default.override {
extensions = [ "rust-src" ];
};Defined in develop/checks/git-hooks/default.nix. Runs on every commit:
| Hook | What it checks |
|---|---|
nixfmt |
Nix file formatting |
deadnix |
Dead code in Nix files |
statix |
Nix anti-patterns |
cargo-check |
Type-checks the crate |
clippy |
Rust lint warnings |
rustfmt |
Rust code formatting |
Dependencies are locked via Cargo.lock. Builds are fully reproducible when combined with Nix’s hashed fetchers. The package builder at develop/packages/default/default.nix reads lockFile directly:
cargoLock.lockFile = ../../../Cargo.lock;rust/
├── flake.nix # flake entrypoint → purr.mkFlake
├── Cargo.toml # package manifest
├── Cargo.lock # pinned dep tree
├── src/
│ └── main.rs # crate entrypoint
├── develop/
│ ├── packages/default/default.nix # nix build → buildRustPackage
│ ├── shells/default/default.nix # nix develop → mkShell
│ └── checks/git-hooks/default.nix # pre-commit hooks
├── .envrc # direnv auto-load
└── .gitignore
- Reproducible: The same lockfile + Nix closure = the same binary every time.
- Guardrails: Zero-warning CI won’t let sloppy code through.
- Editor-ready:
RUST_SRC_PATHwired up sorust-analyzerresolves stdlib sources out of the box. - Offline-capable: All tooling comes from the
/nix/store— no network needed after initial fetch.