Skip to content
LogoLogo

Quick Start

Create a project

nix flake init copies a template into the current directory:

mkdir my-project && cd my-project
nix flake init -t github:nixcafe/develop-templates#node

Add --refresh if Nix may have cached an older version of the template flake. Each template prints the commands it supports when it is copied.

The beans alias

nix registry add beans github:nixcafe/develop-templates
nix flake init -t beans#node

On a host that uses cattery-modules, cattery.nix registers beans through nix.registry.beans.to, so you can skip the first command.

A new GitHub repository

Every template except purr and purr-flake-parts is also a GitHub template repository under nixcafe-develop:

gh repo create my-project --template nixcafe-develop/node --clone

The secrets template lives in nixcafe-develop/nix-secrets. Keep that one private:

gh repo create my-secrets --template nixcafe-develop/nix-secrets --private --clone

Initialize git first

After nix flake init, run this before nix develop:

git init && git add -A

The order matters for three reasons:

  • Nix evaluates a flake in a git repository from the files git tracks. Untracked files, such as a freshly copied develop/ directory, are invisible to it.
  • nix develop installs the pre-commit hooks into .git/hooks, which needs a repository.
  • Some shells read the repository root. The python shell sets REPO_ROOT with git rev-parse --show-toplevel for its editable install, and the secrets template's nix run .#update-secrets writes the generated .age files into the repository.

Later, git add new files before you build or evaluate. git add -N <file> is enough to make Nix see a file without staging its contents.

Enter the shell

nix develop

With direnv, every template ships an .envrc with use flake. Allow it once and the shell loads whenever you cd into the project:

direnv allow

The first Nix command writes flake.lock. Templates do not ship one, so you start from current inputs. Commit it, together with uv.lock or Cargo.lock where the template has one.

Everyday commands

CommandWhat it doesTemplates
nix developOpens the dev shell and installs the hooksAll except purr and purr-flake-parts
nix fmtFormats the Nix files with nixfmt-treeAll except purr-flake-parts
nix flake checkRuns the pre-commit hooks on every fileAll except purr and purr-flake-parts
nix buildBuilds packages.defaultpython, rust
nix flake showLists the outputsAll

The hooks run nixfmt, deadnix, and statix everywhere. Some templates add their own: ruff and ruff-format in python, cargo-check, clippy, and rustfmt in rust, and typstyle in typst. On commit they check the staged files, and nix flake check runs them over the whole repository.

What templates leave out

  • No flake.lock, as described above.
  • No LICENSE. Add the license you want.
  • No default template. nix flake init -t github:nixcafe/develop-templates without a name fails, so always pass #<name>.

Next steps