No description
  • Rust 67.9%
  • Nix 30.4%
  • Typst 1.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-22 04:19:55 +00:00
envs fix(wsp): correct handling on zero paths/libraries 2026-10-21 14:54:48 +01:00
lib pin a specific rust toolchain version 2026-11-22 04:19:55 +00:00
mock-pkgs/local2 fix: package spec MUST have a patch version number 2026-10-21 10:39:36 +01:00
scan-pkg add package scan tests 2026-10-21 09:29:57 +01:00
src fix: typos, minor rewording 2026-10-21 15:20:54 +01:00
tests add local package overrides + test 2026-10-24 15:40:10 +01:00
.gitignore first testable version 2026-10-20 01:27:06 +01:00
Cargo.lock remove dirs dep 2026-10-21 14:51:11 +01:00
Cargo.toml remove dirs dep 2026-10-21 14:51:11 +01:00
flake.lock pin a specific rust toolchain version 2026-11-22 04:19:55 +00:00
flake.nix pin a specific rust toolchain version 2026-11-22 04:19:55 +00:00
README.md fix: typst package derivation -> package 2026-10-24 16:53:58 +01:00
rust-toolchain.toml pin a specific rust toolchain version 2026-11-22 04:19:55 +00:00
rustfmt.toml workspace setup 2026-10-18 18:17:03 +01:00

typst-nix -- typst compilation in a nix derivation

Before you use this flake, please go check out Typix -- a more mature project that does basically the same thing. I am building this package because I believe Typix is not abstract enough and lacks the ability to automatically resolve the dependencies.

How to use

  1. Add to your flake inputs:
inputs.typst-nix.url = "https://git.dzuchun.ing/dzu/typst-nix.git";
  1. Run typst-lock against your typst document.

This flake exposes it at apps.<system>.default, or you may do

cargo install --git https://git.dzuchun.ing/dzu/typst-nix.git

Help text:

Statically resolve and lock `@preview` packages for a Typst project

Usage: typst-lock [OPTIONS] [ENTRYPOINT]

Arguments:
  [ENTRYPOINT]
          `.typ` file to start with, relative to `<ROOT>`

          Defaults to `main.typ`

Options:
      --root <ROOT>
          Project root

          Defaults to CWD

      --lockfile <LOCKFILE>
          Path of the lockfile to write.

          Defaults to `<ROOT>/typst.lock`

      --force
          Even if the lockfile is present at the output location, ignore it and resolve everything from scratch

      --prefetch-url-path <PREFETCH_URL_PATH>
          Path to the `nix-prefetch-url` binary

          Defaults to whatever is first in `PATH`

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

This tool produces a special file at typst.lock (or whatever you pass into --lockfile), that you can commit -- this is a direct Typst equivalent to flake.lock and Cargo.lock.

  1. Call into the nix function.

The main function is located at .lib.compileTypst. You may use aliases at .lib.<system>.compileTypst, if you don't care where pkgs come from.

Signature:

compileTypst :: {
    pkgs,
    # package to take the typst binary from. can also be a function `pkgs -> package`
    typstPackage ? pkgs.typst,
    # possible values: pdf, png, svg, html, bundle
    format ? "pdf",
    # root of the typst project
    rootDir,
    # main typst file
    entrypoint ? "${rootDir}/main.typ",
    # lockfile, representing the dependencies
    lockfile ? "${rootDir}/typst.lock",
    # exposed in Typst as `sys.inputs`. must be an attrset of `toString`-able values
    inputs ? { },
    # exposed in Typst as `sys.inputs`. must be an attrset of paths
    inputFiles ? { },
    # paths to fonts
    fontPaths ? [ ],
    # if set, Typst's own embedded fonts will be ignored
    ignoreEmbeddedFonts ? false,
    # UNIX timestamp exposed by datetime functions
    creationTimestamp ? 0,
    # pretty-format the output
    pretty ? false,
    pages ? null,
    # see typst c --help
    noPdfTags ? false,
    # see typst c --help
    ppi ? 144,
    features ? [ ],
    # an attrset of direct package overrides. keys are namespaces (`local`, `repo`, ...);
    # values are lists of `{ name, version, package }` sets
    overridePackages ? { },
    ...
} -> Derivation

The output of the produced derivation is your compiled file (PDF, PNG, SVG, HTML, or bundle).

Known limitations

  • The typst-lock tool only resolves and locks packages from the Typst universe. Custom and local packages are not resolved automatically, but you can still consume them at compile time via overridePackages (see tests/local_dep).
  • Tool operates on the "fail open" strategy: non-existent or unresolvable packages are skipped with a warning, while errors in your entrypoint are fatal.
  • If the package traversal fails in any way, it will remain in the manifest, but without its dependencies. You will also see an explicit message about this hard failure.
  • Tool only understands imports and includes with literal string sources. This may or may not be relaxed to "pure+local eval values" in the future.
  • All the resolutions and downloads are naive and never retried. If one of the packages you are sure to exist fails, please rerun.
  • Power loss durability is not a goal. If you think that the lockfile is corrupted, just regenerate it.