typst: add fonts to the wrapper

Introduces `typst.wrapper` with the following arguments:

- `packages`. For backwards compatibility, `typst.withPackages f` is
  equivalent to `typst.wrapper { packages = f; }`.
- `fonts` allows specifying extra fonts via `TYPST_FONT_PATHS`.
- `extraWrapperArgs` for extra arguments to `makeWrapper`.
This commit is contained in:
Naïm Camille Favier
2026-01-19 20:52:19 +01:00
parent 3334170f35
commit 6a918ec238
3 changed files with 26 additions and 4 deletions

View File

@@ -15,6 +15,16 @@ typst.withPackages (
)
```
For more customisation options, you can invoke the wrapper directly:
```nix
typst.wrapper {
packages = p: [ ];
fonts = [ ];
extraWrapperArgs = [ ];
}
```
### Handling Outdated Package Hashes {#typst-handling-outdated-package-hashes}
Since **Typst Universe** does not provide a way to fetch a package with a specific hash, the package hashes in `nixpkgs` can sometimes be outdated. To resolve this issue, you can manually override the package source using the following approach:

View File

@@ -71,7 +71,8 @@ rustPlatform.buildRustPackage (finalAttrs: {
passthru = {
updateScript = nix-update-script { };
packages = callPackage ./typst-packages.nix { };
withPackages = callPackage ./with-packages.nix { };
wrapper = callPackage ./wrapper.nix { };
withPackages = ps: finalAttrs.passthru.wrapper { packages = ps; };
};
meta = {

View File

@@ -8,12 +8,18 @@
lib.makeOverridable (
{ ... }@typstPkgs:
f:
{
packages ? (ps: [ ]),
fonts ? [ ],
extraWrapperArgs ? [ ],
}:
buildEnv {
inherit (typst) meta;
name = "${typst.name}-env";
paths = lib.foldl' (acc: p: acc ++ lib.singleton p ++ p.propagatedBuildInputs) [ ] (f typstPkgs);
paths = lib.foldl' (acc: p: acc ++ lib.singleton p ++ p.propagatedBuildInputs) [ ] (
packages typstPkgs
);
pathsToLink = [ "/lib/typst-packages" ];
@@ -28,7 +34,12 @@ lib.makeOverridable (
cp -r ${typst}/share $out/share
mkdir -p $out/bin
makeWrapper "${lib.getExe typst}" "$out/bin/typst" --set TYPST_PACKAGE_CACHE_PATH $TYPST_LIB_DIR
TYPST_FONT_PATHS=${lib.escapeShellArg (lib.concatStringsSep ":" fonts)}
makeWrapper "${lib.getExe typst}" "$out/bin/typst" \
--set TYPST_PACKAGE_CACHE_PATH $TYPST_LIB_DIR \
''${TYPST_FONT_PATHS:+--set TYPST_FONT_PATHS "$TYPST_FONT_PATHS"} \
${lib.escapeShellArgs extraWrapperArgs}
'';
}
) typstPackages