-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
typst: add support to instantiate typst with a set of typst packages
- Loading branch information
1 parent
d4586bd
commit 284eb24
Showing
2 changed files
with
118 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
lib, | ||
buildEnv, | ||
typstPackages, | ||
makeBinaryWrapper, | ||
}: | ||
|
||
let | ||
typstPackagesFor = | ||
typst: | ||
lib.makeOverridable ( | ||
{ ... }@typstPkgs: | ||
f: | ||
let | ||
preparedTypstDeps = f typstPkgs; | ||
expandTypstDeps = | ||
ps: | ||
if ps == [ ] then | ||
ps | ||
else | ||
lib.foldl' (acc: p: acc ++ lib.singleton p ++ expandTypstDeps p.typstDeps) [ ] ps; | ||
in | ||
buildEnv { | ||
name = "${typst.name}-env"; | ||
|
||
paths = lib.unique (expandTypstDeps preparedTypstDeps); | ||
|
||
nativeBuildInputs = [ makeBinaryWrapper ]; | ||
|
||
postBuild = '' | ||
export TYPST_LIB_DIR="$out/lib/typst/packages" | ||
mkdir -p $TYPST_LIB_DIR/preview | ||
for path in $(find $out -type l); do | ||
mv $path $TYPST_LIB_DIR/preview | ||
done | ||
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; | ||
in | ||
{ | ||
inherit typstPackagesFor; | ||
} |