forked from matsavage/DND-5e-LaTeX-Character-Sheet-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
187 lines (166 loc) · 4.29 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
{
description = "Latex DnD 5e character sheet";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils = {
url = "github:numtide/flake-utils";
inputs = {};
};
# latex specific
dnd = {
url = "github:rpgtex/DND-5e-LaTeX-Template";
flake = false;
};
};
outputs = {
nixpkgs,
flake-utils,
dnd,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
texlive = pkgs.texlive.combine {
inherit
(pkgs.texlive)
scheme-minimal
collection-luatex
# Executables:
latexmk
luatex
luahbtex
latex-bin
# For DND 5e latex template (see: their packages.txt):
amsfonts
atbegshi
babel
babel-english
bookman
bookmark
cfr-initials
cm
colortbl
contour
courier
ec
enumitem
environ
epstopdf-pkg
etex-pkg
etoolbox
fancyhdr
fontaxes
fp
geometry
gillius
hang
hyperref
initials
keycommand
kpfonts
kvsetkeys
l3backend
l3kernel
l3packages
latex-fonts
lettrine
lm
ltxcmds
luacolor
microtype
minifp
ms
numprint
oberdiek
pgf
psnfss
ragged2e
tcolorbox
titlesec
tocloft
tools
trimspaces
was
xcolor
xkeyval
xstring
# For this project:
fontspec
gensymb
kpfonts-otf
pdfcol
pstricks
tikzfill
pst-tools
# Needed for lualatex and transparencies:
luapstricks
pdfmanagement-testphase
;
};
buildInputs = [
texlive
# pkgs.ghostscript_headless # needed for the xdv to pdf step
pkgs.gnused
];
pname = "dnd-char-sheet";
version = "1.0";
envVars = {
FONTCONFIG_FILE = pkgs.makeFontsConf {fontDirectories = [./template/fonts];};
TEXINPUTS = "${builtins.toString ./.}//:${dnd}//:";
TTFONTS = "${builtins.toString ./.}//:${dnd}//:";
TEXMFHOME = ".cache";
TEXMFVAR = ".cache/texmf-var";
};
build_character = (
directory: file_name: let
file_name_cleaned = pkgs.lib.removeSuffix ".tex" file_name;
value_derivation = pkgs.stdenv.mkDerivation (pkgs.lib.recursiveUpdate {
name = "${directory}-${file_name_cleaned}-${pname}-${version}";
src = ./.;
inherit buildInputs;
buildPhase = ''
latexmk -interaction=nonstopmode -pdf -lualatex ${directory}/${file_name}
'';
installPhase = ''
mkdir --parents $out/logs
cp ./*.log $out/logs
cp ${file_name_cleaned}.pdf $out
'';
}
envVars);
in
pkgs.lib.nameValuePair file_name_cleaned value_derivation
);
build_from_directory = (directory: let
tex_paths = pkgs.lib.filterAttrs (key: value: value == "regular") (builtins.readDir ./${directory});
tex_files = pkgs.lib.mapAttrs' (name: _: build_character directory name) tex_paths;
all_tex_files = pkgs.symlinkJoin {
name = "${directory}-all";
paths = pkgs.lib.attrValues tex_files;
};
in {
individual = tex_files;
combined = all_tex_files;
});
in rec {
packages =
pkgs.lib.recursiveUpdate {
default = (build_from_directory "characters").combined;
test = (build_from_directory "tests").combined;
}
(build_from_directory "characters").individual;
devShells.default = pkgs.mkShell (pkgs.lib.recursiveUpdate {
packages = with pkgs; [
nil
alejandra
statix
ltex-ls
texlab
zathura
];
inherit buildInputs;
}
envVars);
});
}
# vim: ts=2