Add flake.templates, justfile, and .envrc for direnv

Compared this template against the older nix-templates/templates/rust
("rrrr") ahead of eventually replacing it. Ported the pieces that were
genuinely missing and non-controversial:

- flake.templates.default, so `nix flake init -t <url>` works once
  this repo is published — the actual mechanism a "template" needs.
- justfile wrapping the cargo/nix commands for discoverability.
- .envrc (use flake) for direnv auto-activation.
- `just` added to the dev shell so the justfile is usable without a
  separate install.

Left out on purpose: workspace crate split, tracing/serde/tokio-heavy
example code, docker.nix, nightly coverage toolchain, and copier.yaml —
those make it an opinionated async-service starter rather than a blank
Rust template, and copier.yaml in the old repo was dead configuration
(no file actually referenced its Jinja variables).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ALEXkc7pTro7tF1WcUuKb
This commit is contained in:
2026-08-11 00:50:51 +08:00
parent d61ba8aec2
commit c7303154cc
6 changed files with 100 additions and 2 deletions
+6 -1
View File
@@ -50,6 +50,10 @@ Both paths are meant to converge on the same result — the Nix devShell and the
are built from one shared toolchain/build-args definition (see Architecture below), so what
compiles under `nix build` should also compile under plain `cargo build` inside `nix develop`.
`justfile` wraps the commands above (`just build`, `just test`, `just ci`, `just nix-check`, ...;
run `just` with no args to list them) — available inside `nix develop`. `.envrc` (`use flake`) lets
direnv users skip typing `nix develop` entirely.
## IDE / LSP support
`rust-analyzer` is included in the fenix toolchain (`nix/rust.nix`), and `nix develop`'s
@@ -74,7 +78,8 @@ install, so the LSP sees the same compiler version as the build.
treefmt-nix, wired into both `nix fmt` and the `formatting` check in `flake.nix`.
- **`flake.nix`** ties it together with `flake-parts`: it imports the treefmt module, evaluates
`nix/rust.nix` per-system, and exposes `packages.default`, `checks`, `apps.default`, and
`devShells.default` from its outputs.
`devShells.default` from its outputs. It also declares `flake.templates.default`, so once this
repo is published, `nix flake init -t <url>` scaffolds a new project straight from it.
- **`src/lib.rs`** holds the actual logic (currently just `greet`); `src/main.rs` is a thin `clap`
wrapper around it. Keep new functionality in the lib crate, not `main.rs`, so it stays reachable
from `tests/` and `benches/` (both depend on the `rust_template` lib crate by name, not on the