Nix flake template for Typst documents, built on purr and git-hooks.nix. Part of develop-templates.
Initialize in the current directory:
nix flake init -t "github:nixcafe/develop-templates#typst" --refreshOr register the template flake once under beans:
nix registry add beans "github:nixcafe/develop-templates"
nix flake init -t beans#typstIf you use cattery-modules, beans is already registered.
To create a new GitHub repository directly:
gh repo create my-typst-project --template nixcafe-develop/typst --cloneEnter the shell:
direnv allow
# or
nix developNo flake.lock is shipped. The first Nix command generates one.
typst compile main.typWatch and rebuild on file changes:
typst watch main.typBoth write main.pdf, which is ignored in .gitignore.
| Tool | Role |
|---|---|
typst |
Typst compiler |
tinymist |
Typst LSP server and preview |
typstyle |
Typst formatter |
nixfmt |
Formats Nix files (nix fmt) |
deadnix |
Finds unused Nix bindings |
statix |
Lints Nix files |
Pre-commit hooks for nixfmt, deadnix, statix, and typstyle live in develop/checks/git-hooks/default.nix and install when you enter the shell.
.
├── .envrc
├── .gitignore
├── flake.nix
├── main.typ
├── statix.toml
└── develop/
├── checks/
│ └── git-hooks/
│ └── default.nix
└── shells/
└── default/
└── default.nix
Edit develop/shells/default/default.nix:
packages = with pkgs; [
typst
tinymist
typstyle
nixfmt
deadnix
statix
];Reload with direnv allow or nix develop.
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;
typstyle.enable = true;
};
}nix develop # open dev shell
typst compile main.typ # build main.pdf
typst watch main.typ # rebuild on save
typstyle -i main.typ # format Typst files
nix fmt # format Nix files
nix flake check # run git-hooks check