buildTypstProjectLocal

Returns a derivation for compiling a Typst project and copying the output to the current directory.

This is essentially a script which wraps buildTypstProject.

Using this derivation requires allow-import-from-derivation to be true (which is the default at the time of writing).

More info: https://nixos.org/manual/nix/stable/language/import-from-derivation

Invoking the script produced by this derivation directly is currently unsupported. Instead, use nix run.

See this issue for more information.

Parameters

All parameters accepted by buildTypstProject are also accepted by buildTypstProjectLocal. They are repeated below for convenience.

src

Source containing all local files needed in your Typst project.

fontPaths (optional)

List of sources specifying paths to font files that will be made available to your Typst project. With this, you can compile Typst projects even when the fonts it uses are not available on your system.

Used for setting TYPST_FONT_PATHS (see text#font).

Example

{
  outputs = { nixpkgs, typix }: let
    system = "x86_64-linux";
    pkgs = nixpkgs.legacyPackages.${system};
  in {
    apps.${system}.default = typix.lib.${system}.buildTypstProjectLocal {
      fontPaths = [
        "${pkgs.roboto}/share/fonts/truetype"
      ];
    };
  };
}

installPhaseCommand (optional)

Command (or commands) to run during installPhase.

scriptName (optional)

Name of the script that will be added to the Nix store. You can use this name after entering a development shell to invoke the script.

Default is typst-build.

typstCompileCommand (optional)

Base Typst command to run to compile the project. Other arguments will be appended based on the parameters you supply.

Default is typst compile.

typstOpts (optional)

Attrset specifying command-line options to pass to the typst command.

These are in addition to any options you manually pass in typstCompileCommand.

Default:

{
  format = "pdf";
}

Example

{
  format = "png";
  ppi = 300;
}

...will result in a command like:

typst compile --format png --ppi 300 <source> <output>

typstOutput (optional)

Destination path for Typst output.

If omitted, it will be inferred from typstSource — for example, page.typ will become page.pdf for PDF output.

typstSource (optional)

Typst input file to compile.

Default is main.typ.

virtualPaths (optional)

List of sources that will be made virtually available to your Typst project. Useful for projects which rely on remote resources, such as images or data.

Each element of the list is an attribute set with the following keys:

  • src: path to source directory
  • dest (optional): path where files will be made available (defaults to .)

Instead of an attrset, you may use a path which will be interpreted the same as if you had specified an attrset with just src.

Example

You can specify dependencies in your flake input, and then use them in your project with something like:

{
  inputs = {
    font-awesome = {
      url = "github:FortAwesome/Font-Awesome";
      flake = false;
    };
  };

  outputs = { typix, font-awesome }: let
    system = "x86_64-linux";
  in {
    apps.${system}.default = typix.lib.${system}.buildTypstProjectLocal {
      virtualPaths = [
        {
          dest = "icons";
          src = "${font-awesome}/svgs/regular";
        }
      ];
    };
  };
}

Then, reference the files in Typst:

#image("icons/heart.svg")

Source