Skip to content

Commit 317b71f

Browse files
committed
Add Typst Universe Patches
1 parent a8b11db commit 317b71f

File tree

6 files changed

+58
-9
lines changed

6 files changed

+58
-9
lines changed

default.nix

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,27 @@ in {
2424
meta ? {},
2525
fonts ? [],
2626
typstUniverse ? true,
27+
universePatches ? [],
2728
extraPackages ? {},
2829
file ? "main.typ",
2930
format ? "pdf",
3031
...
3132
} @ args: let
32-
universe' = lib.optionalString typstUniverse ''
33-
mkdir -p $XDG_DATA_HOME/typst/packages
34-
cp -r ${universe}/packages/preview $XDG_DATA_HOME/typst/packages/
35-
'';
33+
universe' = let
34+
patchedUni =
35+
if universePatches == []
36+
then universe
37+
else
38+
final.applyPatches {
39+
name = "universe-patched";
40+
src = universe;
41+
patches = universePatches;
42+
};
43+
in
44+
lib.optionalString typstUniverse ''
45+
mkdir -p $XDG_DATA_HOME/typst/packages
46+
cp -r ${patchedUni}/packages/preview $XDG_DATA_HOME/typst/packages/
47+
'';
3648

3749
userPackages = lib.attrsets.foldlAttrs (shString: namespace: paths:
3850
lib.lists.foldl (accum: path: let
@@ -60,7 +72,7 @@ in {
6072
strictDeps = true;
6173

6274
env.TYPST_FONT_PATHS = "${fontsDrv}";
63-
75+
6476
buildPhase =
6577
args.buildPhase
6678
or (''

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
checks.x86_64-linux = let
2525
pkgs = import nixpkgs {
2626
system = "x86_64-linux";
27-
overlays = [ (import self) ];
27+
overlays = [(import self)];
2828
};
2929
in
3030
builtins.removeAttrs (pkgs.callPackage ./tests {}) ["override" "overrideDerivation"];

template/flake.nix

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
pkgs = import nixpkgs {
2727
inherit system;
28-
overlays = [ (import press) ];
28+
overlays = [(import press)];
2929
};
3030
in {
3131
packages.${system}.default = pkgs.buildTypstDocument {
@@ -57,7 +57,11 @@
5757
];
5858
# [Optional] Patches to the Typst document
5959
# Default: []
60-
typstPatches = []
60+
typstPatches = [];
61+
# [Optional] Patches to the Typst Universe repo
62+
# To apply a patch, it much be a patch to the entire Typst Packages repo.
63+
# Default: []
64+
univerPatches = [];
6165
};
6266
};
6367
}

tests/default.nix

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@
3535
./patch.patch
3636
];
3737
});
38-
38+
39+
patchUni = buildTypstDocument (self: {
40+
name = "patchUni";
41+
src = ./documents;
42+
file = "patchUni.typ";
43+
universePatches = [
44+
./universe.patch
45+
];
46+
});
47+
3948
gitImport = buildTypstDocument (self: {
4049
name = "gitImport";
4150
src = ./documents;

tests/documents/patchUni.typ

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import "@preview/note-me:0.5.0": bote
2+
3+
#bote[
4+
Success!
5+
]

tests/universe.patch

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--- a/packages/preview/note-me/0.5.0/lib.typ
2+
+++ b/packages/preview/note-me/0.5.0/lib.typ
3+
@@ -1,2 +1,2 @@
4+
-#import "note-me.typ": admonition, note, tip, important, warning, caution
5+
-#import "note-me-more.typ": todo
6+
\ No newline at end of file
7+
+#import "note-me.typ": admonition, bote, tip, important, warning, caution
8+
+#import "note-me-more.typ": todo
9+
--- a/packages/preview/note-me/0.5.0/note-me.typ
10+
+++ b/packages/preview/note-me/0.5.0/note-me.typ
11+
@@ -80,7 +80,7 @@
12+
],
13+
)
14+
15+
-#let note(title: "Note", children) = admonition(
16+
+#let bote(title: "Note", children) = admonition(
17+
icon-path: "icons/info.svg",
18+
title: title,
19+
color: rgb(9, 105, 218),

0 commit comments

Comments
 (0)