purr · git-hooks · nix · nixpkgs · nix-flake
Base Nix flake development template — a minimal, reproducible dev shell with Nix formatters and git pre-commit hooks. Built on purr for zero-friction Nix flake scaffolding and git-hooks.nix for automated quality gates. Batteries included: auto-formatting, dead-code removal, and static analysis enforced before every commit.
Part of the develop-templates collection (nix flake init-ready).
nix flake init -t "github:nixcafe/develop-templates#nix" --refreshRegister a short alias:
nix registry add beans "github:nixcafe/develop-templates"
nix flake init -t beans#nixTip: With cattery-modules,
beansis pre-registered.
gh repo create my-nix-project --template nixcafe/nix --clonedirenv allow # auto-load flake on cd
# or without direnv:
nix develop| Tool | Purpose | More |
|---|---|---|
nixfmt |
Canonical Nix formatter | nixfmt |
deadnix |
Scan & remove dead Nix code | deadnix |
statix |
Linter for Nix antipatterns | statix |
All three run as git pre-commit hooks and are available inside the dev shell (nix develop).
Edit develop/shells/default/default.nix and append packages to the list:
{
inputs,
pkgs,
system,
...
}:
pkgs.mkShell {
packages = with pkgs; [
nixfmt
deadnix
statix
just # command runner
alejandra # alternative formatter
];
shellHook = ''
${inputs.self.checks.${system}.git-hooks.shellHook}
'';
buildInputs = inputs.self.checks.${system}.git-hooks.enabledPackages;
}Edit develop/checks/git-hooks/default.nix to enable, disable, or configure hooks:
{ inputs, system, ... }:
inputs.git-hooks.lib.${system}.run {
src = ../../..;
hooks = {
nixfmt.enable = true;
deadnix.enable = true;
statix.enable = true;
# Add more hooks from git-hooks.nix:
# shellcheck.enable = true;
# actionlint.enable = true;
};
}See the full list of available hooks at git-hooks.nix.
Tune the linter in statix.toml at the repo root:
disabled = ["repeated_keys"]
ignore = ['.direnv']
nix_version = '2.4'.
├── flake.nix # Flake entrypoint
├── statix.toml # statix linter config
├── .envrc # direnv: `use flake`
├── .gitignore
│
├── develop/
│ ├── checks/
│ │ └── git-hooks/
│ │ └── default.nix # Pre-commit hooks (nixfmt, deadnix, statix)
│ │
│ └── shells/
│ └── default/
│ └── default.nix # Dev shell packages + shellHook
| Input | URL |
|---|---|
nixpkgs |
https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz |
purr |
https://flakehub.com/f/nixcafe/purr/0.1.*.tar.gz |
git-hooks |
https://flakehub.com/f/cachix/git-hooks.nix/0.1.*.tar.gz |
All inputs follow nixpkgs for a single consistent package set.
nix develop # Enter dev shell
nix flake check # Run all checks (includes git-hooks)
nix fmt # Format flake.nix with nixfmt
statix check . # Lint all Nix files
deadnix -f # Scan and remove dead code