Skip to content

Commit ffa8996

Browse files
committed
flake: refactor and simplify
1 parent 2459e16 commit ffa8996

File tree

3 files changed

+41
-90
lines changed

3 files changed

+41
-90
lines changed

flake.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 10 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
imports = [
2121
inputs.pkgs-by-name-for-flake-parts.flakeModule
2222
./nix/imports/pkgs.nix
23-
inputs.pkgs-by-name-for-flake-parts.flakeModule
2423
];
2524

2625
perSystem =
@@ -34,90 +33,23 @@
3433
# Change here to typst-dev if needed
3534
typst = pkgs.nixpkgs-unstable.typst;
3635

37-
fontsConf = pkgs.symlinkJoin {
38-
name = "typst-fonts";
39-
paths = with pkgs; [
40-
inriafonts
41-
fg-virgil
42-
liberation_ttf
43-
nerd-fonts.inconsolata
44-
newcomputermodern
45-
];
46-
};
47-
48-
mkBuildDocumentDrv =
49-
documentName:
50-
pkgs.stdenvNoCC.mkDerivation {
51-
name = "build-" + documentName;
52-
53-
src = pkgs.lib.cleanSource ./.;
54-
55-
buildInputs = [ typst ];
56-
57-
buildPhase = ''
58-
runHook preBuild
59-
${lib.getExe typst} \
60-
compile \
61-
--root ./. \
62-
--input rev="${inputs.self.rev or ""}" \
63-
--input shortRev="${inputs.self.shortRev or ""}" \
64-
--input builddate="$(date -u -d @${toString (inputs.self.lastModified or "")})" \
65-
--package-path ${inputs.typst-packages}/packages \
66-
--font-path ${fontsConf} \
67-
--ignore-system-fonts \
68-
./src/${documentName}/main.typ \
69-
${documentName}.pdf
70-
71-
runHook postBuild
72-
'';
73-
74-
installPhase = ''
75-
runHook preInstall
76-
77-
install -m640 -D ${documentName}.* -t $out
78-
79-
runHook postInstall
80-
'';
81-
};
82-
83-
mkBuildDocumentScript =
84-
documentName:
85-
pkgs.writeShellApplication {
86-
name = "build-${documentName}";
87-
88-
runtimeInputs = [ typst ];
89-
90-
text = ''
91-
${lib.getExe typst} \
92-
compile \
93-
--root ./. \
94-
--input rev="${inputs.self.rev or ""}" \
95-
--input shortRev="${inputs.self.shortRev or ""}" \
96-
--input builddate="$(date -u -d @${toString (inputs.self.lastModified or "")})" \
97-
--package-path ${inputs.typst-packages}/packages \
98-
--font-path ${fontsConf} \
99-
--ignore-system-fonts \
100-
./src/${documentName}/main.typ \
101-
${documentName}.pdf
102-
'';
103-
};
104-
105-
mkWatchDocumentScript =
36+
mkTypstScript =
37+
action:
10638
documentName:
10739
pkgs.writeShellApplication {
108-
name = "watch-${documentName}";
40+
name = "typst-${action}-${documentName}";
10941

11042
runtimeInputs = [ typst ];
11143

11244
text = ''
11345
${lib.getExe typst} \
114-
watch \
46+
${action} \
11547
--root ./. \
11648
--input rev="${inputs.self.rev or ""}" \
11749
--input shortRev="${inputs.self.shortRev or ""}" \
11850
--input builddate="$(date -u -d @${toString (inputs.self.lastModified or "")})" \
11951
--package-path ${inputs.typst-packages}/packages \
120-
--font-path ${fontsConf} \
52+
--font-path ${config.packages.typst-fonts} \
12153
--ignore-system-fonts \
12254
./src/${documentName}/main.typ \
12355
${documentName}.pdf
@@ -126,7 +58,7 @@
12658

12759
documentDrvs = lib.genAttrs (lib.attrNames (
12860
lib.filterAttrs (k: v: (v == "directory")) (builtins.readDir ./src)
129-
)) (d: mkBuildDocumentDrv d);
61+
)) (d: (mkTypstScript "compile" d));
13062

13163
scriptDrvs =
13264
{
@@ -136,8 +68,8 @@
13668
a: i:
13769
a
13870
// {
139-
"build-${i}" = mkBuildDocumentScript i;
140-
"watch-${i}" = mkWatchDocumentScript i;
71+
"compile-${i}" = (mkTypstScript "compile" i);
72+
"watch-${i}" = (mkTypstScript "watch" i);
14173
}
14274
) { } (lib.attrNames documentDrvs);
14375
in
@@ -158,11 +90,11 @@
15890
echo "Typst version: ${typst.version}"
15991
echo "Typst bin: ${lib.getExe typst}"
16092
echo "Typst packages directory: ${config.packages.typst-packages}"
161-
echo "Typst fonts directory: ${fontsConf}"
93+
echo "Typst fonts directory: ${config.packages.typst-fonts}"
16294
'';
16395

16496
env = {
165-
TYPST_FONT_PATHS = fontsConf;
97+
TYPST_FONT_PATHS = config.packages.typst-fonts;
16698
};
16799
};
168100
};

nix/pkgs/typst-fonts/package.nix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
symlinkJoin,
3+
inriafonts,
4+
fg-virgil,
5+
liberation_ttf,
6+
nerd-fonts,
7+
newcomputermodern,
8+
}:
9+
10+
symlinkJoin {
11+
name = "typst-fonts";
12+
paths = [
13+
inriafonts
14+
fg-virgil
15+
liberation_ttf
16+
nerd-fonts.inconsolata
17+
newcomputermodern
18+
];
19+
}

0 commit comments

Comments
 (0)