Skip to content
LogoLogo

Templates

nix flake init -t github:nixcafe/develop-templates#<name>
NameContentsSource
nixnixfmt, deadnix, statix, and pre-commit hooksnixcafe-develop/nix
nodeNode.js, corepack, ni, Bun, and Denonixcafe-develop/node
pythonPython from requires-python, uv2nix, ruff hooks, and a packagenixcafe-develop/python
rustrust-overlay toolchain, crane package, cargo hooksnixcafe-develop/rust
javaGraalVM CE, Maven, and Gradlenixcafe-develop/java
kotlinGraalVM CE, kotlinc, and Gradlenixcafe-develop/kotlin
latexTeX Live, latexmk, texlab, chktex, and latexindentnixcafe-develop/latex
typsttypst, tinymist, and typstylenixcafe-develop/typst
nix-configNixOS, nix-darwin, and Home Manager hosts with installer imagesnixcafe-develop/nix-config
colmena-confignix-config plus Colmena deploymentnixcafe-develop/colmena-config
secretsage secrets with ragenix and an update-secrets appnixcafe-develop/nix-secrets
purrMinimal purr flake with mkFlakenixcafe/purr
purr-flake-partsMinimal purr flake with flake-partsnixcafe/purr

Language templates

The language templates keep their Nix code out of the way. flake.nix calls purr's mkFlake with src = ./develop, so the shell, the hooks, and any package live under develop/ and the project root holds only your own files:

.envrc
flake.nix                        inputs, purr mkFlake, nixfmt-tree formatter
statix.toml
develop/
  shells/default/default.nix     dev shell
  checks/git-hooks/default.nix   pre-commit hooks

The dev shell reuses inputs.self.checks.${system}.git-hooks for its shellHook and packages, so the hook configuration is written and evaluated once.

nix

A shell for Nix-only projects with nixfmt, deadnix, and statix, plus the matching pre-commit hooks. Use it as the base for a repository of Nix expressions.

node

A shell with nodejs, corepack, ni (@antfu/ni), bun, and deno.

  • ni, nr, nlx, and the other ni commands pick npm, pnpm, Yarn, or Bun from the lock file in the project.
  • The shell puts node_modules/.bin on PATH when it exists and sets COREPACK_ENABLE_DOWNLOAD_PROMPT=0, so corepack-managed package managers install without a prompt.
  • Only the Nix hooks are enabled. Add JavaScript hooks in develop/checks/git-hooks/default.nix.

python

A Python project managed with uv and built by Nix through uv2nix and pyproject.nix.

  • The interpreter comes from the first <major>.<minor> in requires-python. The template's ">=3.12" selects python312.
  • pyproject.toml and uv.lock are the source of truth. nix build produces packages.default from them, and nix run runs the example script.
  • The dev shell has a Nix-built virtualenv with every dependency group, your project installed in editable mode from $REPO_ROOT, and uv. Edits under src/ take effect right away.
  • uv add and uv lock update pyproject.toml and uv.lock but install nothing. UV_NO_SYNC=1 and UV_PYTHON_DOWNLOADS=never keep uv from touching the Nix-managed environment. Reload the shell to pick up new dependencies.
  • Hooks: ruff, ruff-format, and the Nix hooks.
pyproject.toml
uv.lock
src/example/
develop/lib/default.nix              uv workspace and Python package set
develop/packages/default/default.nix application build

rust

A Rust crate built with crane and the latest stable toolchain from rust-overlay.

  • develop/overlays/rust-toolchain/default.nix defines pkgs.rustToolchain with rust-src. The package, the shell, and the hooks all use it, so changing the toolchain there changes it everywhere.
  • nix build runs craneLib.buildDepsOnly first and passes the result as cargoArtifacts, so editing your code does not rebuild the dependencies.
  • The shell gets the package's build inputs (pkg-config, openssl) through inputsFrom and sets RUST_SRC_PATH for rust-analyzer.
  • Hooks: cargo-check, clippy, rustfmt, and the Nix hooks. The cargo hooks use crates vendored from Cargo.lock, because the check sandbox has no network.

java

A shell with GraalVM CE (graalvmPackages.graalvm-ce) as the JDK, Maven built against it, and gradle_9 running on it. Change the jdk binding in develop/shells/default/default.nix to switch JDKs for all three at once.

kotlin

The same GraalVM CE setup as java, with kotlinc instead of Maven. The Kotlin compiler and gradle_9 both run on the GraalVM JDK.

latex

A shell with texliveMedium extended with latexmk, minted, upquote, latexindent, and chktex, plus the texlab language server. minted needs upquote, which is included, so code listings work without extra packages.

latexmk -pdf main.tex

PDF files and the intermediate TeX outputs are ignored in .gitignore.

typst

A shell with typst, the tinymist language server, and the typstyle formatter. typstyle also runs as a pre-commit hook.

typst watch main.typ

Configuration templates

nix-config

A purr flake for NixOS, nix-darwin, and Home Manager that imports cattery-modules through extraModules, with nixpkgsConfig.allowUnfree = true.

PathContents
systems/x86_64-linux/hostname-nixosNixOS desktop with room.desktop.dev and KDE Plasma
systems/x86_64-linux/hostname-serverNixOS server with a root user and IP forwarding
systems/x86_64-linux/hostname-wslNixOS-WSL host
systems/aarch64-darwin/hostname-mbpnix-darwin host with room.desktop.dev
systems/x86_64-linux/{graphical,minimal,minimal-no-zfs}Image-only hosts with images = [ "iso-installer" ] in meta.nix
homes/<arch>-<format>/<user>@<host>Homes linked into the matching host and built as homeConfigurations
lib/host/default.nixUser name, real name, email, time zone, login shell, and SSH keys
lib/secrets/default.nixenable and secretsPath for cattery.secrets

Before you deploy, fill in lib/host/default.nix and generate a hardware.nix for each NixOS host. The NixOS hosts ship placeholder file systems with lib.mkDefault so the flake evaluates before you add real hardware.

nix build .#images.graphical.iso-installer
sudo nixos-rebuild switch --flake .#hostname-nixos

Secrets are off by default. The my-secrets input points at the nix-secrets template until you point it at your own repository and set enable = true.

colmena-config

nix-config plus Colmena. It adds a colmena input, colmena in the dev shell, and a colmenaHive output built from nixosConfigurations. Every NixOS host becomes a Colmena node, and SSH targets come from colmena/colmenaHive/deployments.nix:

{
  hostname-server.deployment = {
    targetHost = "hostname-server";
    targetPort = 22;
    targetUser = "root";
  };
}
colmena apply --on hostname-server

Image-only hosts are not in nixosConfigurations, so they are not in the hive either.

secrets

A repository for age-encrypted secrets, edited with ragenix and laid out the way cattery.secrets reads them.

  • Public keys and machines live in develop/lib/keys/default.nix. The files to encrypt are listed in develop/lib/settings/default.nix. The root secrets.nix reads both, so you never edit it by hand.
  • The template ships plain-text placeholder .age files and placeholder keys. Replace the keys with your own, then delete the placeholders before you create real secrets.
  • A file's path decides its recipients. hosts/<machine>/global/ goes to that machine, its users, and the recovery keys. hosts/<machine>/users/<user>/ and shared/users/<user>/ go to that user. shared/global/ goes to every machine with sharedSecretRecipient = true (the default), their users, and the recovery keys.
  • sharedSecretRecipient = false keeps a machine out of shared/global secrets while it still appears in the generated SSH config.
  • nix run .#update-secrets builds the generated secrets, a known_hosts file and an SSH config for the machines in ssh.fromMachines, and writes the encrypted files into the repository.
ragenix -e shared/global/wireguard/wg0.conf.age
nix run .#update-secrets

The dev shell has ragenix, age-plugin-yubikey, and a few editors. Keep the repository private and use it from nix-config or colmena-config through the my-secrets input.

purr starters

purr

The template/default flake from purr: a mkFlake call with src = ./., namespace = "myproject", and nixfmt-tree as the formatter. Add directories such as packages/, shells/, or systems/, and purr turns them into outputs. It has no dev shell or hooks.

purr-flake-parts

The template/flake-parts flake from purr: flake-parts with purr.flakeModules.default imported and purr.enable = true. It has no dev shell, hooks, or formatter.

See the purr docs for what each directory produces.