Skip to content

RossSmyth/press

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Press

GitHub Actions Workflow Status

A library for building Typst documents with Nix. Goals:

  1. Hermetic document building
  2. Support non-Typst Universe packages
  3. Easy devShell support, just use inputsFrom and it supports your packages and fonts with incremental development.
  4. Integrates with Nixpkg's typstPackages
  5. Supports key-values inputs (Typst's sys.inputs dictionary)
  6. Nixpkg's fonts

Quickstart

mkdir my-typst-document
cd my-typst-document
nix flake init --template github:RossSmyth/press
nix build

Status

Basically done. In "maintenence mode". Let me know if you find any issues or have feature requests.

See the template for full API details and documentation.

Limitations:

  • Cannot automatically detect third-party package dependencies (i.e. through the extraPackages attribute)

Usage

Just import the overlay.

pkgs = import nixpkgs {
  overlays = [ (import press) ];
};
...
document = pkgs.buildTypstDocument {
  name = "myDoc";
  src = ./.;
};

With Nixpkg's Typst Universe integration:

document = pkgs.buildTypstDocument {
  name = "myDoc";
  src = ./.;
  # Adds note-me from Nixpkgs
  typstEnv = p: [ p.note-me ];
};

If you want to use a non-Universe package:

Recommended by extending the Nixpkgs typstPackages package set:

let
pkgs = import nixpkgs {
  overlays = [
    (import press)
    (final: prev:
      typstPackages = prev.typstPackages.extend (finalTypst: _: {
        cool-package = final.buildTypstPackage {
          pname = "cool-package";
          version = "1.0";
          src = coolPackageSrc;
          typstDeps = [ finalTypst.note-me ];
        }; 
      })
    )
  ];
};
in
pkgs.buildTypstDocument {
  name = "myDoc";
  src = ./.;
  typstEnv = p: [ p.treet p.cool-package ];
} 

Or you can also use them directly, or if you want them in a custom namespace.

Warning

If pname and version are not specified, IFD will be used to determine the name and version.

pkgs.buildTypstDocument {
  name = myDoc;
  src = ./.;
  extraPackages = {
    local = [
      somePackage
      anotherPack
    ];

    foospace = [ fooPackage ];

    # Can specify the name and version explicitly to avoid IFD.
    coolspace = [
      {
        pname = coolPackage;
        version = "1.0";
        src = coolPackage;
      }
    ];
  };
}

If you want to use custom fonts:

documents = pkgs.buildTypstDocument {
  name = "myDoc";
  src = ./.;
  fonts = [
    pkgs.roboto
  ];
};

Then for a devShell:

devShell = mkShell {
  inputsFrom = [ document ];
  packages = [
    tinymist
    typstyle
  ];
};

Where local is the package namespace, and somePackage is a store path that has a typst.toml file in it. You can put packages in whatever namespace you want, not just local.

See the template for more API details.

About

Typst document building in nix

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 7