Nix flake template for Typst documents. The dev shell provides Typst, the tinymist language server, and nixfmt, deadnix, and statix for Nix files. Pre-commit hooks for the Nix tools are enabled and installed by the shell hook. The flake is built with purr and uses git-hooks.nix.
Part of the develop-templates collection.
Create the project files in the current directory:
nix flake init -t "github:nixcafe/develop-templates#typst" --refreshRegister the collection once to use the shorter name:
nix registry add beans "github:nixcafe/develop-templates"
nix flake init -t beans#typstWith cattery-modules, beans is already registered.
You can also create a repository from the template repository:
gh repo create my-typst-project --template nixcafe-develop/typst --cloneEnter the dev shell:
nix developIf direnv is installed, direnv allow loads the shell when you enter the directory. The template includes an .envrc that calls use flake.
The template does not include a flake.lock. The first nix develop resolves the inputs and writes one.
typst compile main.typTo rebuild on changes:
typst watch main.typBoth commands write main.pdf, which is listed in .gitignore.
| Tool | Purpose |
|---|---|
typst |
Typst compiler |
tinymist |
LSP server with completion, diagnostics, and preview |
nixfmt |
Nix formatter |
deadnix |
Finds dead code in Nix files |
statix |
Nix linter |
The sample main.typ shows headings, math, lists, a code block, and a table.
The pre-commit hooks for nixfmt, deadnix, and statix are enabled in develop/checks/git-hooks/default.nix. The shell hook installs them when you enter the dev shell.
The flake also sets allowUnfree = true and uses pkgs.nixfmt as the formatter, so nix fmt formats the Nix files.
nix develop # enter the dev shell
direnv allow # load the shell through direnv
typst compile main.typ # build main.pdf
typst watch main.typ # rebuild on changes
nix fmt # format Nix files with nixfmtdevelop/shells/default/default.nix contains the package list. Add tools as needed:
packages = with pkgs; [
typst
tinymist
typstfmt # formatter
nixfmt
deadnix
statix
];Run direnv allow or nix develop to reload the shell after changing the list.
develop/checks/git-hooks/default.nix enables three hooks:
{ inputs, system, ... }:
inputs.git-hooks.lib.${system}.run {
src = ../../..;
hooks = {
nixfmt.enable = true;
deadnix.enable = true;
statix.enable = true;
};
}Set enable = false to skip a hook, or add entries from git-hooks.nix.
.
├── flake.nix # Flake entry point
├── main.typ # Sample Typst document
├── develop/
│ ├── checks/
│ │ └── git-hooks/
│ │ └── default.nix # Pre-commit hook definitions
│ └── shells/
│ └── default/
│ └── default.nix # Dev shell packages and shell hook
├── statix.toml # statix configuration
├── .envrc # direnv: use flake
└── .gitignore