master
Found via an end-to-end test of nix flake init -> rename -> nix flake check: renaming can reorder `use` statements alphabetically (e.g. "acme_widget" now sorts before "criterion"), and treefmt's rustfmt (nixpkgs) disagreed with cargo fmt's rustfmt (fenix toolchain) on edition-2024 import grouping, so the formatting check failed right after a clean rename. - nix/treefmt.nix: pin programs.rustfmt.edition = "2024" to match Cargo.toml, so treefmt and cargo fmt agree. - scripts/rename-project.sh: auto-format (cargo fmt, falling back to nix fmt) after renaming, and note that nix commands need git-tracked files. - README.md/CLAUDE.md: document that `nix flake init -t` doesn't git-init for you, and every nix command needs `git add` first. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018ALEXkc7pTro7tF1WcUuKb
rust_template
A minimal Rust project template: a clap CLI backed by a library crate, with unit tests, an
integration test, a criterion benchmark, and a Nix flake (crane + fenix) — so it builds the same
way with plain cargo or with nix.
Using this template
- Copy/clone this repo, or scaffold fresh with
nix flake init -t <this-repo-url>. - If you used
nix flake init(no.gityet), rungit init && git add -A— Nix flakes only see git-tracked files, so everynixcommand below needs this first. - Rename the placeholder crate name:
./scripts/rename-project.sh my_project cd .. && mv rust_template my_project && cd my_project git add -A # stage the rename before running any nix command again - Build whatever you actually came here for — replace
greetinsrc/lib.rs, extend the CLI insrc/main.rs, add your own tests and benchmarks.
Building and running
With Cargo (needs Rust installed, or run inside nix develop):
cargo run -- Zeke # build + run, prints "Hello, Zeke!"
cargo build --release
cargo test # unit + integration tests
cargo bench # criterion benchmark
With Nix (no local Rust install needed):
nix develop # dev shell with the pinned toolchain + tools
nix build # produces ./result/bin/rust_template
nix run -- Zeke # build + run
nix flake check # clippy, fmt, doc, audit, tests — all in one go
nix fmt # format Rust, Nix, and TOML files
If you have direnv installed, direnv allow activates the dev shell
automatically on cd (see .envrc).
just (available inside nix develop) wraps the common commands above — run just to list them.
See CLAUDE.md for more detail on the project layout and how the pieces fit together.
Description
Languages
Nix
59.5%
Shell
21.2%
Just
10.3%
Rust
9%