-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
228 lines (218 loc) · 7.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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
{
description = "CV LaTeX Document";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
flake-utils.url = "github:numtide/flake-utils";
vale-nix = {
url = "github:icewind1991/vale-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
yaml.url = "github:jim3692/yaml.nix";
};
outputs = { self, nixpkgs, flake-utils, vale-nix, yaml }:
with flake-utils.lib; eachSystem allSystems (system:
let
overlays = [ vale-nix.overlays.default ];
pkgs = (import nixpkgs) { inherit system overlays; };
valeLint = (pkgs.valeWithConfig (let
lib = pkgs.lib;
resume = yaml.lib.fromYaml ./resume.yaml;
separateString = s: (
lib.strings.splitString " " (builtins.replaceStrings ["/" ","] ["" ""] s)
);
in {
packages = styles: with styles; [proselint readability];
vocab = { accept = (
# Add all names to vocab
(lib.strings.splitString " " resume.basics.name)
++ (lib.lists.flatten (
map (r: lib.strings.splitString " " r.name) resume.references)
)
++ (map (p: p.username) resume.basics.profiles)
# Add all netkork names (LinkedIn, GitHub, etc) to vocab
++ (map (p: p.network) resume.basics.profiles)
# Add all company names to vocab
++ (lib.lists.flatten (map (w: separateString w.name) resume.work))
# Add all keywrd names (usually names of tech) to vocab
++ (lib.lists.flatten (map (w: map (k: separateString k) w.keywords) resume.work))
++ (lib.lists.flatten (map (s: map (k: separateString k) s.keywords) resume.skills))
++ [
"personalSummary"
"startDate"
"endDate"
"bulletpoints"
"calc" "flexbox" "polyfill" "polyfills"
"components" "pipelines"
"fullstack" "Fullstack"
"customisable"
"demoable"
"devshell"
]
); };
formatOptions = {
"*" = {
basedOnStyles = ["Vale" "proselint" "Readability"];
};
};
}));
inputResume = "resume.yaml";
inputFilename = ./main.tex;
outputFilename = "cv.pdf";
# pkgs = nixpkgs.legacyPackages.${system};
tex = pkgs.texlive.combine {
inherit (pkgs.texlive) scheme-basic latex-bin latexmk luatex
xcolor geometry eqparbox environ etoolbox microtype luacode luatexbase
paralist enumitem hyperref
tabularray multirow makecell tcolorbox
markdown gobble
pgf xifthen csvsimple
fancyhdr fancyvrb titlesec fontspec nunito fontawesome5;
};
texSetupEnv = /* bash */ ''
DIR=$(mktemp -d)
mkdir -p "$DIR/.texcache/texmf-var"
mkdir -p "$DIR/.home" # a clean home is needed for the font cache
'';
texEnv = /* bash */ ''
env \
HOME="$DIR/.home" \
TEXMFHOME="$DIR/.texcache/home" \
TEXMFVAR="$DIR/.cache/texmf-var" \
OSFONTDIR=${pkgs.fira-mono}/share/fonts'';
latexmkCmd = {
name ? "",
previewer ? "",
copyOutput ? true,
inputYaml ? inputResume,
inputTex ? inputFilename,
outputPdf ? outputFilename
}: pkgs.writeShellApplication {
name = if name != "" then name else (if previewer == "" then "latex-cv-build" else "latex-cv-preview");
runtimeInputs = [ pkgs.coreutils pkgs.gnused pkgs.fira-mono tex ];
text = /* bash */ ''
INPUT_YAML="${inputYaml}"
INPUT_TEX="${inputTex}"
${ if copyOutput then
''OUTPUT_PDF="${outputPdf}"''
else "" }
${texSetupEnv}
echo -e "Compiling pdf from:\n\tyaml: $INPUT_YAML\n\ttex: $INPUT_TEX"
sed "s|resume-example.yaml|$INPUT_YAML|g" "$INPUT_TEX" > "$DIR/input.tex"
${texEnv} \
latexmk -interaction=nonstopmode -pdf -lualatex \
-output-directory="$DIR" \
-norc \
${
if previewer == "" then
''-f "$DIR/input.tex"''
else (/* bash */ '' \
-e "\$pdf_previewer = 'start ${previewer}';" \
-e "@default_files = ('$DIR/input.tex');" \
-e "set_tex_cmds( '--interaction=batchmode %O %S' );" \
-pvc -time \
<(cat "$INPUT_TEX" | sed "s|resume-example.yaml|${INPUT_YAML}|g")
'')
}
${ if copyOutput then
''cp "$DIR/input.pdf" "$OUTPUT_PDF"'' else "" }
rm -rf "$DIR"
'';
};
cvBaseDerivationOptions = {
copyOutput = true;
inputYaml = "$1";
inputTex = "$2";
outputPdf = "$3";
};
cvBaseDerivationScript = commandName: /* bash */ ''
INPUT_RESUME="''${1:-"${inputResume}"}"
INPUT_TEX="''${2:-"${inputFilename}"}"
OUTPUT_PDF="''${3:-"${outputFilename}"}"
${commandName} "$INPUT_RESUME" "$INPUT_TEX" "$OUTPUT_PDF"
'';
cvBuilder = pkgs.writeShellApplication {
name = "latex-cv-build";
runtimeInputs = [ (
latexmkCmd ({
name = "latex-cv-build";
} // cvBaseDerivationOptions)
) ];
text = cvBaseDerivationScript "latex-cv-build";
};
cvPreviewer = pkgs.writeShellApplication {
name = "latex-cv-preview";
runtimeInputs = [ (
latexmkCmd ({
name = "latex-cv-preview";
previewer = "${pkgs.zathura}/bin/zathura";
} // cvBaseDerivationOptions)
) ];
text = cvBaseDerivationScript "latex-cv-preview";
};
in rec {
devShells = {
# Unified shell environment
default = pkgs.mkShell
{
buildInputs = [
cvBuilder
cvPreviewer
valeLint
];
};
};
packages = {
lint = pkgs.writeShellApplication {
name = "lintYaml";
runtimeInputs = [ pkgs.gnused pkgs.yq valeLint ];
# vale --output=JSON <(yq '${pkgs.lib.strings.concatStringsSep " | " [
text = /* bash */ ''
INPUT_RESUME="''${1:-"resume.yaml"}"
exec \
vale <(yq '${pkgs.lib.strings.concatStringsSep " | " [
''{basics, work, projects}''
''with_entries(select(.value != null))''
''del(.. | .url?, .email?, .username?, .keywords?)''
''del( .basics.profiles )''
]}' "$INPUT_RESUME" | sed "s/\bol’ /old /g")
'';
};
document = pkgs.stdenvNoCC.mkDerivation rec {
name = "latex-cv-document";
src = self;
buildInputs = [ pkgs.coreutils (
latexmkCmd { name = "latex-cv-build"; copyOutput = true; }
) ];
phases = ["unpackPhase" "buildPhase" "installPhase"];
buildPhase = /* bash */ ''
export PATH="${pkgs.lib.makeBinPath buildInputs}";
latex-cv-build
'';
installPhase = ''
mkdir -p $out
cp ${outputFilename} $out/
'';
};
build = cvBuilder;
preview = cvPreviewer;
yamlToPdf = { inputYaml }:
pkgs.stdenvNoCC.mkDerivation (let
buildInputs = [ pkgs.coreutils cvBuilder ];
in {
name = "yaml-to-pdf";
src = self;
inherit buildInputs;
phases = ["unpackPhase" "buildPhase" "installPhase"];
buildPhase = ''
export PATH="${pkgs.lib.makeBinPath buildInputs}";
mkdir -p $out
latex-cv-build "${inputYaml}" "${inputFilename}" cv.pdf
'';
installPhase = ''
cp cv.pdf $out/
'';
});
};
defaultPackage = packages.document;
});
}