-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
130 lines (110 loc) · 3.78 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
typst-dev.url = "github:typst/typst";
typst-packages = {
flake = false;
url = "github:typst/packages/main";
};
pkgs-by-name-for-flake-parts.url = "github:drupol/pkgs-by-name-for-flake-parts";
};
outputs =
inputs@{ ... }:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [
inputs.pkgs-by-name-for-flake-parts.flakeModule
./nix/imports/pkgs.nix
];
perSystem =
{
pkgs,
lib,
config,
...
}:
let
# Change here to typst-dev if needed
typst = pkgs.nixpkgs-unstable.typst;
mkTypstScript =
action: documentName:
pkgs.writeShellApplication {
name = "typst-${action}-${documentName}";
runtimeInputs = [ typst ];
text = ''
${lib.getExe typst} \
${action} \
--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 ${config.packages.typst-fonts} \
--ignore-system-fonts \
./src/${documentName}/main.typ \
${documentName}.pdf
'';
};
mkBuildDocumentDrv =
action: documentName:
pkgs.stdenvNoCC.mkDerivation {
pname = "typst-${action}-${documentName}";
version = typst.version;
src = pkgs.lib.cleanSource ./.;
buildInputs = [ typst ];
buildPhase = ''
runHook preBuild
${lib.getExe (mkTypstScript "compile" documentName)}
runHook postBuild
'';
installPhase = ''
runHook preInstall
install -m640 -D ${documentName}.* -t $out
runHook postInstall
'';
};
documentDrvs = lib.genAttrs (lib.attrNames (
lib.filterAttrs (k: v: (v == "directory")) (builtins.readDir ./src)
)) (d: (mkBuildDocumentDrv "compile" d));
scriptDrvs =
{
"sign-pdf" = config.packages.sign-pdf;
}
// lib.foldl' (
a: i:
a
// {
"compile-${i}" = (mkTypstScript "compile" i);
"watch-${i}" = (mkTypstScript "watch" i);
}
) { } (lib.attrNames documentDrvs);
in
{
pkgsDirectory = ./nix/pkgs;
packages = documentDrvs;
devShells.default = pkgs.mkShellNoCC {
packages = (lib.attrValues scriptDrvs) ++ [
typst
pkgs.gnuplot
pkgs.tinymist
pkgs.typstyle
config.packages.weasel
config.packages.passive
config.packages.dups
];
shellHook = ''
echo "Typst version: ${typst.version}"
echo "Typst bin: ${lib.getExe typst}"
echo "Typst packages directory: ${config.packages.typst-packages}"
echo "Typst fonts directory: ${config.packages.typst-fonts}"
'';
env = {
TYPST_FONT_PATHS = config.packages.typst-fonts;
};
};
};
};
}