Skip to content

Commit 33a4258

Browse files
jbgiRossSmyth
authored andcommitted
Add support for --input arguments
1 parent a7cada4 commit 33a4258

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

default.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ in
2323
"extraPackages"
2424
"fonts"
2525
"typstEnv"
26+
"inputs"
2627
];
2728

2829
# All the drv args
@@ -37,6 +38,7 @@ in
3738
typstEnv ? (_: [ ]),
3839
extraPackages ? { },
3940
file ? "main.typ",
41+
inputs ? { },
4042
format ? "pdf",
4143
...
4244
}@args:
@@ -110,6 +112,10 @@ in
110112
111113
typst c ${file} ${lib.optionalString verbose "--verbose"} ${
112114
lib.optionalString (format == "html") "--features html"
115+
} ${
116+
lib.concatStringsSep " " (
117+
lib.mapAttrsToList (name: value: "--input ${name}=${lib.escapeShellArg value}") inputs
118+
)
113119
} -f ${format} $out
114120
115121
runHook postBuild

template/flake.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
# This is relative to the directory input above.
4444
# Default: "main.typ"
4545
file = "main.typ";
46+
# [Optional] Key-value attribute set passed as --input arguments to typst
47+
# (available as the `sys.inputs` dictionary)
48+
inputs = {
49+
"language" = "fr";
50+
};
4651
# [Optional] Typst universe package selection
4752
#
4853
# Pass in a function that accept an attrset of Typst pacakges,

tests/default.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,13 @@ in
9595
local = [ note-meGh ];
9696
};
9797
};
98+
99+
inputs = mkTest {
100+
name = "inputs";
101+
inputs = {
102+
language = "en";
103+
name = "John Doe";
104+
};
105+
};
106+
98107
}

tests/documents/inputs.typ

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Value of "sys.inputs.language" is #sys.inputs.language
2+
3+
#if sys.inputs.name != "John Doe" {
4+
panic("Expected 'John Doe' in 'sys.inputs.name' but got " + sys.inputs.flag)
5+
}

0 commit comments

Comments
 (0)