typst: add support to instantiate typst with a set of typst packages

This commit is contained in:
Gongqi Huang 2025-01-01 15:57:58 +01:00
parent d976d61d9e
commit c47a2a8ac7
4 changed files with 42 additions and 2 deletions

View file

@ -115,7 +115,7 @@ class TypstPackage:
hash=source_hash, hash=source_hash,
typstDeps=[ typstDeps=[
self.package_name_full(p, v) self.package_name_full(p, v)
for p, v in sorted(self.deps, key=lambda x: x[0]) for p, v in sorted(self.deps, key=lambda x: (x[0], Version(x[1])))
], ],
description=self.description, description=self.description,
license=self.license_tokens(), license=self.license_tokens(),

View file

@ -8,6 +8,7 @@
xz, xz,
nix-update-script, nix-update-script,
versionCheckHook, versionCheckHook,
callPackage,
}: }:
rustPlatform.buildRustPackage (finalAttrs: { rustPlatform.buildRustPackage (finalAttrs: {
@ -60,7 +61,11 @@ rustPlatform.buildRustPackage (finalAttrs: {
versionCheckProgramArg = [ "--version" ]; versionCheckProgramArg = [ "--version" ];
doInstallCheck = true; doInstallCheck = true;
passthru.updateScript = nix-update-script { }; passthru = {
updateScript = nix-update-script { };
packages = callPackage ./typst-packages.nix { };
withPackages = callPackage ./with-packages.nix { };
};
meta = { meta = {
changelog = "https://github.com/typst/typst/releases/tag/v${finalAttrs.version}"; changelog = "https://github.com/typst/typst/releases/tag/v${finalAttrs.version}";

View file

@ -0,0 +1,33 @@
{
lib,
buildEnv,
typstPackages,
makeBinaryWrapper,
typst,
}:
lib.makeOverridable (
{ ... }@typstPkgs:
f:
buildEnv {
name = "${typst.name}-env";
paths = lib.foldl' (acc: p: acc ++ lib.singleton p ++ p.propagatedBuildInputs) [ ] (f typstPkgs);
pathsToLink = [ "/lib/typst-packages" ];
nativeBuildInputs = [ makeBinaryWrapper ];
postBuild = ''
export TYPST_LIB_DIR="$out/lib/typst/packages"
mkdir -p $TYPST_LIB_DIR
mv $out/lib/typst-packages $TYPST_LIB_DIR/preview
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
'';
}
) typstPackages

View file

@ -15287,6 +15287,8 @@ with pkgs;
buildTypstPackage = callPackage ../build-support/build-typst-package.nix { }; buildTypstPackage = callPackage ../build-support/build-typst-package.nix { };
typstPackages = typst.packages;
ueberzug = with python3Packages; toPythonApplication ueberzug; ueberzug = with python3Packages; toPythonApplication ueberzug;
ueberzugpp = callPackage ../by-name/ue/ueberzugpp/package.nix { ueberzugpp = callPackage ../by-name/ue/ueberzugpp/package.nix {