Fix formatting drift after rename, and document git-init requirement

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
This commit is contained in:
2026-08-11 01:06:58 +08:00
parent c7303154cc
commit f07e0c08c8
4 changed files with 33 additions and 6 deletions
+7 -3
View File
@@ -96,9 +96,13 @@ install, so the LSP sees the same compiler version as the build.
`scripts/rename-project.sh <new_snake_case_name>` replaces every `rust_template` occurrence
(crate name in `Cargo.toml`, the `pname`/binary name in `nix/rust.nix` and `flake.nix`, and the
`use rust_template::...` imports in `src/main.rs`, `tests/greet.rs`, `benches/greet.rs`), then
regenerates `Cargo.lock`. It does not rename the project directory itself — that's a manual `mv`
afterward (the script prints the exact command). Run `nix flake check` after renaming to confirm
everything still resolves.
regenerates `Cargo.lock` and reformats (`cargo fmt`/`nix fmt`) — the rename can flip `use`
statements out of alphabetical order (e.g. renaming to something that sorts before `criterion`),
which would otherwise fail the `treefmt` check on the next `nix flake check`. It does not rename
the project directory itself — that's a manual `mv` afterward (the script prints the exact
command). If the tree isn't git-tracked yet (e.g. straight after `nix flake init -t`), run
`git add -A` before *any* `nix` command, including the rename script's own `nix fmt` fallback —
flakes only see git-tracked files.
## Keeping this file current