Skip to content

Commit

Permalink
flake: get rid of the typst factory, use command flags
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 27, 2024
1 parent 238611b commit dc9b2f2
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,42 +42,25 @@
];
};

typst-wrapper-factory =
typstDrv: typst-packages: typstFontPaths:
pkgs.writeShellApplication {
name = "typst-wrapper";

runtimeInputs = [
typstDrv
typst-packages
];

text = ''
TYPST_FONT_PATHS=${typstFontPaths} XDG_CACHE_HOME=${typst-packages} ${lib.getExe typstDrv} "$@"
'';
};

typst-wrapper = typst-wrapper-factory typst config.packages.typst-packages fontsConf;

mkBuildDocumentDrv =
documentName:
pkgs.stdenvNoCC.mkDerivation {
name = "build-" + documentName;

src = pkgs.lib.cleanSource ./.;

buildInputs = [ typst-wrapper ];

buildPhase = ''
runHook preBuild
${lib.getExe typst-wrapper} \
${lib.getExe typst} \
compile \
--root ./. \
--input rev="${inputs.self.rev or ""}" \
--input shortRev="${inputs.self.shortRev or ""}" \
--input builddate="$(date -u -d @${toString (inputs.self.lastModified or "")})" \
--package-path ${inputs.typst-packages}/packages \
--font-path ${fontsConf} \
--ignore-system-fonts \
./src/${documentName}/main.typ \
${documentName}.pdf
Expand All @@ -98,16 +81,18 @@
pkgs.writeShellApplication {
name = "build-${documentName}";

runtimeInputs = [ typst-wrapper ];
runtimeInputs = [ typst ];

text = ''
${lib.getExe typst-wrapper} \
${lib.getExe typst} \
compile \
--root ./. \
--input rev="${inputs.self.rev or ""}" \
--input shortRev="${inputs.self.shortRev or ""}" \
--input builddate="$(date -u -d @${toString (inputs.self.lastModified or "")})" \
--package-path ${inputs.typst-packages}/packages \
--font-path ${fontsConf} \
--ignore-system-fonts \
./src/${documentName}/main.typ \
${documentName}.pdf
'';
Expand All @@ -118,16 +103,18 @@
pkgs.writeShellApplication {
name = "watch-${documentName}";

runtimeInputs = [ typst-wrapper ];
runtimeInputs = [ typst ];

text = ''
${lib.getExe typst-wrapper} \
${lib.getExe typst} \
watch \
--root ./. \
--input rev="${inputs.self.rev or ""}" \
--input shortRev="${inputs.self.shortRev or ""}" \
--input builddate="$(date -u -d @${toString (inputs.self.lastModified or "")})" \
--package-path ${inputs.typst-packages}/packages \
--font-path ${fontsConf} \
--ignore-system-fonts \
./src/${documentName}/main.typ \
${documentName}.pdf
'';
Expand Down Expand Up @@ -157,15 +144,13 @@
devShells.default = pkgs.mkShellNoCC {
packages = (lib.attrValues scriptDrvs) ++ [
typst
typst-wrapper
pkgs.gnuplot
pkgs.pympress
];

shellHook = ''
echo "Typst version: ${typst.version}"
echo "Typst bin: ${lib.getExe typst}"
echo "Typst wrapper bin: ${lib.getExe typst-wrapper}"
echo "Typst packages directory: ${config.packages.typst-packages}"
echo "Typst fonts directory: ${fontsConf}"
'';
Expand Down

0 comments on commit dc9b2f2

Please sign in to comment.