doc/languages-frameworks/typst: Format Nix expressions

This commit is contained in:
Gongqi Huang 2025-04-17 15:09:36 -04:00
parent 3c24ed2f03
commit 788fee2a09

View file

@ -7,10 +7,12 @@ Typst can be configured to include packages from [Typst Universe](https://typst.
You can create a custom Typst environment with a selected set of packages from **Typst Universe** using the following code. It is also possible to specify a Typst package with a specific version (e.g., `cetz_0_3_0`). A package without a version number will always refer to its latest version. You can create a custom Typst environment with a selected set of packages from **Typst Universe** using the following code. It is also possible to specify a Typst package with a specific version (e.g., `cetz_0_3_0`). A package without a version number will always refer to its latest version.
```nix ```nix
typst.withPackages (p: with p; [ typst.withPackages (
p: with p; [
polylux_0_4_0 polylux_0_4_0
cetz_0_3_0 cetz_0_3_0
]) ]
)
``` ```
### Handling Outdated Package Hashes {#typst-handling-outdated-package-hashes} ### Handling Outdated Package Hashes {#typst-handling-outdated-package-hashes}
@ -18,18 +20,24 @@ typst.withPackages (p: with p; [
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: 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:
```nix ```nix
typst.withPackages.override (old: { typst.withPackages.override
typstPackages = old.typstPackages.extend (_: previous: { (old: {
typstPackages = old.typstPackages.extend (
_: previous: {
polylux_0_4_0 = previous.polylux_0_4_0.overrideAttrs (oldPolylux: { polylux_0_4_0 = previous.polylux_0_4_0.overrideAttrs (oldPolylux: {
src = oldPolylux.src.overrideAttrs { src = oldPolylux.src.overrideAttrs {
outputHash = YourUpToDatePolyluxHash; outputHash = YourUpToDatePolyluxHash;
}; };
}); });
}); }
}) (p: with p; [ );
})
(
p: with p; [
polylux_0_4_0 polylux_0_4_0
cetz_0_3_0 cetz_0_3_0
]) ]
)
``` ```
## Custom Packages {#typst-custom-packages} ## Custom Packages {#typst-custom-packages}
@ -39,12 +47,15 @@ typst.withPackages.override (old: {
Here's how to define a custom Typst package: Here's how to define a custom Typst package:
```nix ```nix
{ buildTypstPackage, typstPackages, fetchzip }: {
buildTypstPackage,
typstPackages,
}:
buildTypstPackage (finalAttrs: { buildTypstPackage (finalAttrs: {
pname = "my-typst-package"; pname = "my-typst-package";
version = "0.0.1"; version = "0.0.1";
src = fetchzip { ... }; src = ./.;
typstDeps = with typstPackages; [ cetz_0_3_0 ]; typstDeps = with typstPackages; [ cetz_0_3_0 ];
}) })
``` ```