From c47a2a8ac726f3463581dde8ac3cf5324dd050c9 Mon Sep 17 00:00:00 2001 From: Gongqi Huang Date: Wed, 1 Jan 2025 15:57:58 +0100 Subject: [PATCH] typst: add support to instantiate typst with a set of typst packages --- maintainers/scripts/update-typst-packages.py | 2 +- pkgs/by-name/ty/typst/package.nix | 7 ++++- pkgs/by-name/ty/typst/with-packages.nix | 33 ++++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 pkgs/by-name/ty/typst/with-packages.nix diff --git a/maintainers/scripts/update-typst-packages.py b/maintainers/scripts/update-typst-packages.py index 345bf2804631..2264f97d7706 100755 --- a/maintainers/scripts/update-typst-packages.py +++ b/maintainers/scripts/update-typst-packages.py @@ -115,7 +115,7 @@ class TypstPackage: hash=source_hash, typstDeps=[ 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, license=self.license_tokens(), diff --git a/pkgs/by-name/ty/typst/package.nix b/pkgs/by-name/ty/typst/package.nix index 14f8bce13750..133c9522636a 100644 --- a/pkgs/by-name/ty/typst/package.nix +++ b/pkgs/by-name/ty/typst/package.nix @@ -8,6 +8,7 @@ xz, nix-update-script, versionCheckHook, + callPackage, }: rustPlatform.buildRustPackage (finalAttrs: { @@ -60,7 +61,11 @@ rustPlatform.buildRustPackage (finalAttrs: { versionCheckProgramArg = [ "--version" ]; doInstallCheck = true; - passthru.updateScript = nix-update-script { }; + passthru = { + updateScript = nix-update-script { }; + packages = callPackage ./typst-packages.nix { }; + withPackages = callPackage ./with-packages.nix { }; + }; meta = { changelog = "https://github.com/typst/typst/releases/tag/v${finalAttrs.version}"; diff --git a/pkgs/by-name/ty/typst/with-packages.nix b/pkgs/by-name/ty/typst/with-packages.nix new file mode 100644 index 000000000000..b142a0cbbe99 --- /dev/null +++ b/pkgs/by-name/ty/typst/with-packages.nix @@ -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 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b6c170299879..9052e6987ae6 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -15287,6 +15287,8 @@ with pkgs; buildTypstPackage = callPackage ../build-support/build-typst-package.nix { }; + typstPackages = typst.packages; + ueberzug = with python3Packages; toPythonApplication ueberzug; ueberzugpp = callPackage ../by-name/ue/ueberzugpp/package.nix {