-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathflake.nix
202 lines (178 loc) · 6.11 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
{
description = "jsonresume-nix";
inputs.flake-utils.url = "flake-utils";
outputs = {
self,
flake-utils,
nixpkgs,
...
} @ inputs:
{
# Flake outputs
templates.default = {
path = ./template;
description = "Template to build jsonresume with nix";
};
}
// flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
in {
# Specify formatter package for "nix fmt ." and "nix fmt . -- --check"
formatter = pkgs.alejandra;
# Set up nix develop shell environment
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.resumed
pkgs.nodejs
];
};
# Check output to run checks for all themes
checks.themes = let
builderAttrs =
lib.filterAttrs
(name: _: lib.strings.hasPrefix "resumed-" name)
self.packages.${system};
in
pkgs.stdenv.mkDerivation {
name = "themes-checks";
src = ./template;
buildPhase =
''
cp resume.sample.json resume.json
''
+ (builtins.concatStringsSep "\n\n"
(lib.attrValues (lib.mapAttrs
(name: value: ''
# Build using builder ${name}
${lib.getExe value}
mv resume.html ${name}.html
'')
builderAttrs)));
installPhase =
''
mkdir $out
''
+ (builtins.concatStringsSep "\n\n"
(lib.attrValues (
lib.mapAttrs
(name: _: ''
mv ${name}.html $out
'')
builderAttrs
)));
};
lib = {
buildLiveServer = builderDerivation:
pkgs.writeShellApplication {
name = "live-entr-reload-server";
runtimeInputs = [
pkgs.entr
pkgs.nodePackages.live-server
pkgs.xe
# Include the desired builders program that cointains `resumed-render`
builderDerivation
];
text = ''
resumed-render
live-server --watch=resume.html --open=resume.html --wait=300 &
# We want to not expand $1 in the xe argument
# shellcheck disable=SC2016
printf "\n%s" resume.{toml,nix,json} |
xe -s 'test -f "$1" && echo "$1"' |
entr -p resumed-render
'';
};
buildPrintToPdf = {
builderDerivation,
format ? "A4",
}:
pkgs.writeShellApplication {
name = "print-to-pdf";
runtimeInputs = [
pkgs.puppeteer-cli
pkgs.nodePackages.live-server
# Include the desired builders program that cointains `resumed-render`
builderDerivation
];
text = ''
PORT=$(shuf -i 2000-65000 -n 1)
resumed-render
live-server --host=127.0.0.1 --port="$PORT" --wait=300 --no-browser &
LIVE_SERVER_PID=$!
puppeteer print "http://127.0.0.1:$PORT/resume.html" resume.pdf --format ${format}
kill "$LIVE_SERVER_PID"
'';
};
buildThemeBuilder = themeName: let
themePkg = pkgs.callPackage ./themes/jsonresume-theme-${themeName} {};
in
pkgs.writeShellApplication {
name = "resumed-render";
runtimeInputs = [
self.packages.${system}.fmt-as-json
pkgs.resumed
];
text = ''
# Convert resume.nix to resume.json
fmt-as-json
# Render resume.json
resumed render \
--theme ${themePkg}/lib/node_modules/jsonresume-theme-${themeName}/index.js
'';
};
};
# Expose packages for themes and resumed used
packages = let
# Shorthand for the buildThemeBuilder from lib
inherit (self.lib.${system}) buildThemeBuilder;
in {
# Resumed package used
inherit (pkgs) resumed;
# Themes
resumed-elegant = buildThemeBuilder "elegant";
resumed-full = buildThemeBuilder "full";
resumed-fullmoon = buildThemeBuilder "fullmoon";
resumed-kendall = buildThemeBuilder "kendall";
resumed-macchiato = buildThemeBuilder "macchiato";
resumed-stackoverflow = buildThemeBuilder "stackoverflow";
fmt-as-json = pkgs.writeShellApplication {
name = "fmt-as-json";
runtimeInputs = [
pkgs.findutils
pkgs.jq
pkgs.nix
pkgs.resumed
pkgs.yq-go
];
text = ''
set -eou pipefail
yamlresume="$(find . \( -name 'resume.yaml' -o -name 'resume.yml' \) | head -1 || echo)"
if test -e "./resume.nix"; then
echo "Converting ./resume.nix to ./resume.json" 1>&2
nix-instantiate --eval -E 'builtins.toJSON (import ./resume.nix)' \
| jq -r \
| jq > resume.json
elif test -e "./resume.toml"; then
echo "Converting ./resume.toml to ./resume.json" 1>&2
nix-instantiate --eval -E 'builtins.toJSON (builtins.fromTOML (builtins.readFile ./resume.toml))' \
| jq -r \
| jq > resume.json
elif [[ $yamlresume != "" ]]; then
echo "Converting $yamlresume to ./resume.json" 1>&2
yq -o=json '.' "$yamlresume" > resume.json
elif test -e "./resume.json"; then
echo "Found ./resume.json, not touching it" 1>&2
else
echo "No resume of any supported format found, currently looking for" 1>&2
echo "any of ./resume.(nix|toml|json|yaml|yml)" 1>&2
exit 2
fi
echo "Running validation of ./resume.json" 1>&2
resumed validate
'';
};
};
})
// {inherit inputs;};
}