-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
284 lines (239 loc) · 8.57 KB
/
flake.nix
File metadata and controls
284 lines (239 loc) · 8.57 KB
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
{
description = "The Agentic Coding Playbook: From Idea to Production in 6 Weeks";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
# Node.js dependencies (installed via npm in shell hook)
nodejs = pkgs.nodejs_20;
# Python with required packages
python = pkgs.python3.withPackages (ps: with ps; [
pyyaml
]);
# TeXLive with XeLaTeX and required packages for Pandoc PDF generation
# Using scheme-medium which includes most common packages needed for Pandoc
texlive = pkgs.texlive.combine {
inherit (pkgs.texlive) scheme-medium
# Additional packages for XeLaTeX and Pandoc
xetex
fontspec
unicode-math
polyglossia
# Document structure and formatting
geometry
hyperref
xcolor
listings
fancyhdr
titlesec
tocloft
# Typography and layout
parskip
setspace
caption
float
# Additional utilities
l3packages
xkeyval
etoolbox
booktabs
upquote
fontawesome5
;
};
# Build scripts
buildScripts = pkgs.stdenv.mkDerivation {
name = "agentic-coding-book-scripts";
src = ./.;
buildInputs = [
nodejs
pkgs.pandoc
texlive
python
pkgs.bash
pkgs.coreutils
pkgs.findutils
pkgs.gnused
pkgs.gawk
];
buildPhase = ''
# Install npm dependencies
npm ci --prefer-offline --no-audit
'';
installPhase = ''
mkdir -p $out/bin
# Copy scripts
cp -r scripts $out/
cp -r book $out/
cp -r diagrams $out/
cp package.json package-lock.json $out/
cp -r node_modules $out/
# Create wrapper scripts
cat > $out/bin/build-pdf <<'EOF'
#!/usr/bin/env bash
cd $out && bash $out/scripts/build-pdf.sh
EOF
chmod +x $out/bin/build-pdf
cat > $out/bin/validate <<'EOF'
#!/usr/bin/env bash
cd $out && bash $out/scripts/validate.sh
EOF
chmod +x $out/bin/validate
'';
};
in
{
# Development shell
devShells.default = pkgs.mkShell {
name = "agentic-coding-book-dev";
buildInputs = [
# Core build tools
nodejs
pkgs.pandoc
texlive
python
# Chromium for Mermaid diagram rendering (Puppeteer)
pkgs.chromium
# Shell utilities for scripts
pkgs.bash
pkgs.coreutils
pkgs.findutils
pkgs.gnused
pkgs.gawk
pkgs.which
# Optional but useful
pkgs.gnumake
];
shellHook = ''
# Configure Puppeteer to use Nix-provided Chromium
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
export PUPPETEER_EXECUTABLE_PATH="${pkgs.chromium}/bin/chromium"
# Disable sandboxing for Chromium in containers/Nix environments
export PUPPETEER_ARGS="--no-sandbox --disable-setuid-sandbox"
echo "Agentic Coding Book Development Environment"
echo "============================================"
echo ""
echo "Build tools:"
echo " Node.js: $(node --version)"
echo " Pandoc: $(pandoc --version | head -1)"
echo " Python: $(python --version)"
echo " TeX Live: $(xelatex --version | head -1)"
echo " Chromium: $(chromium --version)"
echo ""
echo "Available commands:"
echo " npm install - Install Node.js dependencies"
echo " npm run build:pdf - Build PDF book"
echo " npm run validate - Run all validation checks"
echo " npm run validate:links - Validate links"
echo " npm run build:mermaid - Render Mermaid diagrams"
echo " npm test - Run tests"
echo ""
# Install npm dependencies if not already installed
if [ ! -d "node_modules" ]; then
echo "Installing npm dependencies..."
npm install
fi
echo "Ready to build!"
echo "============================================"
'';
# Environment variables
PROJECT_ROOT = builtins.toString ./.;
# Ensure scripts can find node_modules/.bin
shellPath = "${nodejs}/bin:$PATH";
};
# Applications that can be run with `nix run`
apps = {
# Build PDF: nix run .#build-pdf
build-pdf = flake-utils.lib.mkApp {
drv = pkgs.writeShellScriptBin "build-pdf" ''
export PATH="${nodejs}/bin:${pkgs.pandoc}/bin:${texlive}/bin:${python}/bin:${pkgs.bash}/bin:${pkgs.coreutils}/bin:${pkgs.findutils}/bin:${pkgs.gnused}/bin:${pkgs.gawk}/bin:$PATH"
if [ ! -d "node_modules" ]; then
echo "Installing dependencies..."
npm install
fi
bash scripts/build-pdf.sh "$@"
'';
};
# Validate: nix run .#validate
validate = flake-utils.lib.mkApp {
drv = pkgs.writeShellScriptBin "validate" ''
export PATH="${nodejs}/bin:${python}/bin:${pkgs.chromium}/bin:${pkgs.bash}/bin:${pkgs.coreutils}/bin:$PATH"
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
export PUPPETEER_EXECUTABLE_PATH="${pkgs.chromium}/bin/chromium"
if [ ! -d "node_modules" ]; then
echo "Installing dependencies..."
npm install
fi
bash scripts/validate.sh
'';
};
# Validate links: nix run .#validate-links
validate-links = flake-utils.lib.mkApp {
drv = pkgs.writeShellScriptBin "validate-links" ''
export PATH="${nodejs}/bin:${pkgs.bash}/bin:${pkgs.coreutils}/bin:$PATH"
if [ ! -d "node_modules" ]; then
echo "Installing dependencies..."
npm install
fi
bash scripts/validate-links.sh
'';
};
# Build Mermaid diagrams: nix run .#build-mermaid
build-mermaid = flake-utils.lib.mkApp {
drv = pkgs.writeShellScriptBin "build-mermaid" ''
export PATH="${nodejs}/bin:${pkgs.chromium}/bin:${pkgs.coreutils}/bin:$PATH"
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
export PUPPETEER_EXECUTABLE_PATH="${pkgs.chromium}/bin/chromium"
if [ ! -d "node_modules" ]; then
echo "Installing dependencies..."
npm install
fi
node scripts/render-mermaid.js
'';
};
};
# Default app
apps.default = self.apps.${system}.build-pdf;
# Package for the book (builds PDF)
packages.default = pkgs.stdenv.mkDerivation {
name = "agentic-coding-book";
version = "0.1.0";
src = ./.;
nativeBuildInputs = [
nodejs
pkgs.pandoc
texlive
python
pkgs.chromium
];
buildPhase = ''
export HOME=$TMPDIR
# Configure Puppeteer to use Nix-provided Chromium
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
export PUPPETEER_EXECUTABLE_PATH="${pkgs.chromium}/bin/chromium"
# Install npm dependencies
npm ci --prefer-offline --no-audit
# Render Mermaid diagrams
npm run build:mermaid
# Build PDF
bash scripts/build-pdf.sh
'';
installPhase = ''
mkdir -p $out
cp output/agentic-coding-book.pdf $out/
'';
meta = with pkgs.lib; {
description = "The Agentic Coding Playbook: From Idea to Production in 6 Weeks";
license = licenses.cc-by-40;
platforms = platforms.unix;
};
};
}
);
}