Nix flake template for Nix projects, built on purr and git-hooks.nix. Part of develop-templates.
Initialize in the current directory:
nix flake init -t "github:nixcafe/develop-templates#nix" --refreshOr register the template flake once under beans:
nix registry add beans "github:nixcafe/develop-templates"
nix flake init -t beans#nixIf you use cattery-modules, beans is already registered.
To create a new GitHub repository directly:
gh repo create my-nix-project --template nixcafe-develop/nix --cloneEnter the shell:
direnv allow
# or
nix developNo flake.lock is shipped. The first Nix command generates one.
| Tool | Role |
|---|---|
nixfmt |
Formats Nix files (nix fmt) |
deadnix |
Finds unused Nix bindings |
statix |
Lints Nix files |
All three tools are in the dev shell and enabled as git pre-commit hooks. Entering the shell installs the hooks. deadnix only checks and fails on dead code. Run deadnix --edit . to remove unused bindings.
.
├── .envrc
├── .gitignore
├── flake.nix
├── statix.toml
└── develop/
├── checks/
│ └── git-hooks/
│ └── default.nix
└── shells/
└── default/
└── default.nix
Edit develop/shells/default/default.nix:
packages = with pkgs; [
nixfmt
deadnix
statix
just
];Keep shellHook and buildInputs wired to gitHooks so pre-commit hooks stay active.
Edit develop/checks/git-hooks/default.nix:
{ inputs, system, ... }:
inputs.git-hooks.lib.${system}.run {
src = ../../..;
hooks = {
nixfmt.enable = true;
deadnix.enable = true;
statix.enable = true;
};
}Adjust statix.toml at the repository root:
disabled = ["repeated_keys"]
ignore = ['.direnv']
nix_version = '2.4'nix develop # open dev shell
nix fmt # format Nix files
nix flake check # run git-hooks check
statix check . # lint Nix files
deadnix --fail . # check for dead code
deadnix --edit . # remove dead code