-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathdevenv-module.nix
More file actions
631 lines (574 loc) · 31.3 KB
/
Copy pathdevenv-module.nix
File metadata and controls
631 lines (574 loc) · 31.3 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
/*
flake-parts module for setting the local IHP devenv shell
this is different from the devenv environment used by IHP apps!
that is defined in flake-module.nix
*/
{ self, inputs }:
{
perSystem = { config, system, nix-filter, pkgs, lib, ... }:
let
ihpLib = config.packages.ihp-env-var-backwards-compat;
# Wrap a package's check phase with a temporary PostgreSQL server
withTestPostgres = pkg: pkg.overrideAttrs (old: {
nativeCheckInputs = (old.nativeCheckInputs or []) ++ [ pkgs.postgresql ];
preCheck = ''
${old.preCheck or ""}
export PGDATA="$TMPDIR/pgdata"
export PGHOST="$TMPDIR/pghost"
mkdir -p "$PGHOST"
initdb -D "$PGDATA" --no-locale --encoding=UTF8
echo "unix_socket_directories = '$PGHOST'" >> "$PGDATA/postgresql.conf"
echo "listen_addresses = '''" >> "$PGDATA/postgresql.conf"
pg_ctl -D "$PGDATA" -l "$TMPDIR/pg.log" start
export DATABASE_URL="postgresql:///postgres?host=$PGHOST"
export IHP_MIGRATE_TEST_DATABASE_URL="$DATABASE_URL"
'';
postCheck = ''
pg_ctl -D "$PGDATA" stop || true
${old.postCheck or ""}
'';
});
in
{
_module.args.pkgs = import inputs.nixpkgs { inherit system; overlays = [ self.overlays.default ]; config = { }; };
apps.migrate = {
type = "app";
program = "${pkgs.ghc.ihp-migrate}/bin/migrate";
meta = {
description = "Apply migrations to the database";
};
};
# Use `nix flake check --impure` to run tests and check that all ihp packages are building succesfully
checks = {
# Checks devShells
ihp-devShell = self.devShells.${system}.default;
boilerplate-devShell = inputs.ihp-boilerplate.devShells.${system}.default;
}
# Add all package outputs to the checks
// (lib.filterAttrs (n: v: lib.isDerivation v && n != "default") self.packages.${system})
# Add all ihp-boilerplate packages to the checks
// (lib.mapAttrs' (n: v: { name = "boilerplate-${n}"; value = v; }) (lib.filterAttrs (n: v: lib.isDerivation v
&& n != "default"
&& n != "unoptimized-docker-image" && n != "optimized-docker-image" # Docker imagee builds are very slow, so we ignore them
) inputs.ihp-boilerplate.packages.${system}))
# Override checks that need a running PostgreSQL for integration tests
// {
default = withTestPostgres self.packages.${system}.default;
ihp-datasync = withTestPostgres self.packages.${system}.ihp-datasync;
ihp-migrate = withTestPostgres pkgs.ghc.ihp-migrate;
ihp-typed-sql = withTestPostgres self.packages.${system}.ihp-typed-sql;
ihp-pglistener = withTestPostgres pkgs.ghc.ihp-pglistener;
}
# HSX parser benchmark: build and run to catch performance regressions
// {
ihp-hsx-bench = (pkgs.haskell.lib.doBenchmark pkgs.ghc.ihp-hsx).overrideAttrs (old: {
postCheck = (old.postCheck or "") + ''
./Setup bench --benchmark-options='+RTS -T -RTS --csv bench-results.csv'
# Compare allocations (column 4) against baseline.
# Allocations are deterministic — same code = same count — so
# any increase signals a real regression, not noise.
${pkgs.gawk}/bin/awk -F, '
NR==FNR && FNR>1 { baseline[$1]=$4; next }
FNR>1 {
name=$1; alloc=$4; base=baseline[name]
if (base > 0 && alloc > base * 1.1) {
printf "REGRESSION: %s allocates %d bytes (baseline %d, +%.0f%%)\n", name, alloc, base, (alloc-base)/base*100
fail=1
}
}
END { if (fail) exit 1 }
' bench-baseline.csv bench-results.csv
'';
});
}
# Integration test: a minimal IHP app that exercises controllers, views, models, HSX, and withIHPApp
// {
integration-test = pkgs.stdenv.mkDerivation {
name = "ihp-integration-test";
src = self;
sourceRoot = "source/integration-test";
nativeBuildInputs = [
(pkgs.ghc.ghc.withPackages (p: with p; [
ihp ihp-hsx ihp-hspec ihp-ide ihp-schema-compiler
ihp-typed-sql
hspec
]))
pkgs.gnumake
pkgs.postgresql
];
buildPhase = ''
export IHP_LIB=${ihpLib}
# Start temporary PostgreSQL
export PGDATA="$TMPDIR/pgdata"
export PGHOST="$TMPDIR/pghost"
mkdir -p "$PGHOST"
initdb -D "$PGDATA" --no-locale --encoding=UTF8
echo "unix_socket_directories = '$PGHOST'" >> "$PGDATA/postgresql.conf"
echo "listen_addresses = '''" >> "$PGDATA/postgresql.conf"
pg_ctl -D "$PGDATA" -l "$TMPDIR/pg.log" start
# Create the test database (withIHPApp replaces '/app' in the URL)
createdb -h "$PGHOST" app
export DATABASE_URL="postgresql:///app?host=$PGHOST"
# Test/TypedSqlSpec.hs uses [typedSql| … |], which describes each
# query against DATABASE_URL at COMPILE time, so the schema must
# exist before we compile. (withIHPApp creates its own per-test
# databases at runtime; this load only serves the compile-time
# describe.) Load IHP's schema first, then the app's.
psql -h "$PGHOST" -d app -v ON_ERROR_STOP=1 -f ${self}/ihp-schema-compiler/data/IHPSchema.sql
psql -h "$PGHOST" -d app -v ON_ERROR_STOP=1 -f Application/Schema.sql
# Generate types from Schema.sql
make -f $IHP_LIB/lib/IHP/Makefile.dist build/Generated/Types.hs
# Compile and run integration tests
GHC_EXTS=$(make -f $IHP_LIB/lib/IHP/Makefile.dist print-ghc-extensions | sed 's/-fbyte-code//g')
ghc --make \
$GHC_EXTS \
-threaded \
-i. -ibuild -iConfig \
-package-env - \
-package ihp -package ihp-hspec -package ihp-typed-sql -package hspec \
-main-is Test.Main \
Test/Main.hs -o test-runner
./test-runner
# Cleanup
pg_ctl -D "$PGDATA" stop || true
'';
installPhase = ''
touch $out
'';
};
}
# GHC 9.12 compatibility checks (build and test all IHP packages)
// (let
ghc912 = pkgs.ghc912;
ihpPackageNames = [
"ihp-ide" "ihp-hsx" "ihp-schema-compiler"
"ihp-postgres-parser" "ihp-pagehead"
"ihp-modal" "ihp-mail"
"ihp-migrate" "ihp-openai" "ihp-ssc" "ihp-graphql"
"ihp-datasync-typescript" "ihp-sitemap"
"ihp-job-dashboard" "ihp-imagemagick"
"ihp-hspec" "ihp-welcome" "ihp-zip"
"wai-asset-path" "wai-flash-messages" "wai-request-params"
"wai-session-maybe" "wai-session-clientsession-deferred"
];
in lib.listToAttrs (map (name: {
name = "ghc912-${name}";
value = ghc912.${name};
}) ihpPackageNames))
# GHC 9.12 packages that need a running PostgreSQL for their tests
// {
ghc912-ihp = withTestPostgres pkgs.ghc912.ihp;
ghc912-ihp-datasync = withTestPostgres pkgs.ghc912.ihp-datasync;
ghc912-ihp-typed-sql = withTestPostgres pkgs.ghc912.ihp-typed-sql;
ghc912-ihp-pglistener = withTestPostgres pkgs.ghc912.ihp-pglistener;
}
# GHC 9.14 compatibility checks (build and test all IHP packages)
// (lib.optionalAttrs (pkgs.haskell.packages ? ghc914) (let
ghc914 = pkgs.ghc914;
ihpPackageNames = [
"ihp-ide" "ihp-hsx" "ihp-schema-compiler"
"ihp-postgres-parser" "ihp-pagehead"
"ihp-modal" "ihp-mail"
"ihp-migrate" "ihp-openai" "ihp-ssc" "ihp-graphql"
"ihp-datasync-typescript" "ihp-sitemap"
"ihp-job-dashboard" "ihp-imagemagick"
"ihp-hspec" "ihp-welcome"
"wai-asset-path" "wai-flash-messages" "wai-request-params"
"wai-session-maybe" "wai-session-clientsession-deferred"
# ihp-zip excluded: Hackage 0.1.1 fails to configure under GHC 9.14
# (zip-archive dependency resolution issue)
];
in lib.listToAttrs (map (name: {
name = "ghc914-${name}";
value = ghc914.${name};
}) ihpPackageNames)
# GHC 9.14 packages that need a running PostgreSQL for their tests
// {
ghc914-ihp = withTestPostgres pkgs.ghc914.ihp;
ghc914-ihp-datasync = withTestPostgres pkgs.ghc914.ihp-datasync;
ghc914-ihp-typed-sql = withTestPostgres pkgs.ghc914.ihp-typed-sql;
ghc914-ihp-pglistener = withTestPostgres pkgs.ghc914.ihp-pglistener;
}))
;
devenv.shells.default = {
packages = with pkgs; [ cabal2nix ];
containers = lib.mkForce {}; # https://github.com/cachix/devenv/issues/528
languages.haskell.enable = true;
languages.haskell.package =
pkgs.ghc.ghc.withPackages (p: with p; [
# Copied from ihp.nix
base
classy-prelude
directory
string-conversions
warp
warp-systemd
wai
mtl
blaze-html
blaze-markup
wai-extra
http-types
inflections
text
postgresql-simple
hasql
hasql-notifications
hasql-pool
ihp-pglistener
hasql-dynamic-statements
hasql-implicits
hasql-transaction
hasql-mapping
hasql-postgresql-types
postgresql-types
wai-app-static
wai-util
aeson
uuid
wai-session-maybe
wai-session-clientsession-deferred
clientsession
pwstore-fast
template-haskell
haskell-src-meta
random-strings
interpolate
websockets
wai-websockets
mime-mail
mime-mail-ses
smtp-mail
attoparsec
case-insensitive
http-media
cookie
process
unix
fsnotify
countable-inflections
typerep-map
basic-prelude
data-default
regex-tdfa
resource-pool
wreq
deepseq
uri-encode
parser-combinators
ip
fast-logger
minio-hs
temporary-ospath
wai-cors
random
cereal-text
neat-interpolation
unagi-chan
with-utf8
# Development Specific Tools (not in ihp.nix)
hspec
ihp-hsx
postgresql-simple-postgresql-types
postgresql-syntax
tasty-bench
# Packages needed for ghci to load IHP modules
slugger
megaparsec
cryptohash
pwstore-fast
vault
http-streams
HsOpenSSL
http-streams
io-streams
network-uri
]);
scripts.fastbuild.exec = ''
cabal build --flag FastBuild
'';
languages.haskell.stack.enable = false; # Stack is not used in IHP
languages.haskell.lsp.package = pkgs.ghc.haskell-language-server;
};
packages = {
default = pkgs.ghc.ihp;
ide = pkgs.ghc.ihp-ide;
ihp-static =
let
jquery = version: hash: pkgs.fetchurl {
url = "https://code.jquery.com/jquery-${version}";
sha256 = hash;
};
bootstrapBase = version: "https://cdn.jsdelivr.net/npm/bootstrap@${version}/dist";
bootstrapCss = version: hash: pkgs.fetchurl {
url = "${bootstrapBase version}/css/bootstrap.min.css";
sha256 = hash;
};
bootstrapJs = version: hash: pkgs.fetchurl {
url = "${bootstrapBase version}/js/bootstrap.min.js";
sha256 = hash;
};
bootstrap538css = bootstrapCss "5.3.8" "1pnyvfp2n8qzyp167h9rvg93msmcf09hsl6hnpwy2gkskkcjflyq";
bootstrap538js = bootstrapJs "5.3.8" "01r295gwq51aq6kb0znj7yymaz6lry4h914kivc7y939bn4i83vv";
bootstrap521css = bootstrapCss "5.2.1" "1l7sy8l7vbbck4mrbvwpq2ssk1hmk2h0qa4gpz5ygsm491iwjcr9";
bootstrap521js = bootstrapJs "5.2.1" "0cx8khby1jg3xcmjbqas79zdsfi7jmvjs00ypi4d140ycch9z1wh";
bootstrap45cssmap = pkgs.fetchurl {
url = "https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css.map";
sha256 = "17jzy6x2shrj805r0czhsz0psjxm5vlv70ipybk8rqz4k7lbcm6j";
};
bootstrap45jsmap = pkgs.fetchurl {
url = "https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js.map";
sha256 = "1fagbzf8qmf338r7qzap55xbj84nsrn91ad4pbq39hwrmi21fb5j";
};
# Select2 — pinned to develop branch (includes jQuery 4 support, PR #6332)
select2commit = "595494a72fee67b0a61c64701cbb72e3121f97b9";
select2js = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/select2/select2/${select2commit}/dist/js/select2.min.js";
sha256 = "1y0j8qwdzkhcp1kn04fbr4hl89x87wi1lkhnirpd5gkc2sb06764";
};
select2css = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/select2/select2/${select2commit}/dist/css/select2.min.css";
sha256 = "1fi1qdiybi30adg8vcqqa6n0jz7c658kv0z39bkvm2ama0i4g2s2";
};
in
pkgs.symlinkJoin {
name = "ihp-static";
paths = [
("${self}/ihp/data/static")
(pkgs.linkFarm "ihp-vendor-js" [
# jQuery — current version
{ name = "vendor/jquery-4.0.0.min.js"; path = jquery "4.0.0.min.js" "1amdfbjdqncpv9x00n8f8xg43nvaapwfiq6kypx8nzyrkbm4d99r"; }
{ name = "vendor/jquery-4.0.0.slim.min.js"; path = jquery "4.0.0.slim.min.js" "01x39qb1rbdz6n2y5j7yd3i420f6x9aw6miki2wny8n7bnzsjcgh"; }
# jQuery — backwards compatibility
{ name = "vendor/jquery-3.7.1.min.js"; path = jquery "3.7.1.min.js" "06hb7y19azzim1k53d1gw78fq6whw7s1qj7hpxf08sqz4kfr76pw"; }
{ name = "vendor/jquery-3.7.1.slim.min.js"; path = jquery "3.7.1.slim.min.js" "1ks0qcs51imwgxf88j1g89isdcznxzc50iv5wjb90fky82ryyqcj"; }
{ name = "vendor/jquery-3.6.0.min.js"; path = jquery "3.6.0.min.js" "0vpylcvvq148xv92k4z2yns3nya80qk1kfjsqs29qlw9fgxj65gz"; }
{ name = "vendor/jquery-3.6.0.slim.min.js"; path = jquery "3.6.0.slim.min.js" "04p56k5isbhhiv8j25jxqhynchw4qxixnvisfm41kdm23j9bkdxv"; }
{ name = "vendor/jquery-3.5.0.min.js"; path = jquery "3.5.0.min.js" "1965r7pswaffbrj42iwyr7ar922gx4yjfgy7w1w41di5mvcwvp64"; }
{ name = "vendor/jquery-3.2.1.slim.min.js"; path = jquery "3.2.1.slim.min.js" "16739f77k16kxyf3ngi6841j07wmjc7qm8jbvjik66xihw494rck"; }
# Bootstrap 5.3.8 — versioned path for apps
{ name = "vendor/bootstrap-5.3.8/bootstrap.min.css"; path = bootstrap538css; }
{ name = "vendor/bootstrap-5.3.8/bootstrap.min.js"; path = bootstrap538js; }
# Bootstrap 5.3.8 — generic path (used by IDE ToolServer)
{ name = "vendor/bootstrap.min.css"; path = bootstrap538css; }
{ name = "vendor/bootstrap.min.js"; path = bootstrap538js; }
# Bootstrap 5.2.1 — backwards compatibility
{ name = "vendor/bootstrap-5.2.1/bootstrap.min.css"; path = bootstrap521css; }
{ name = "vendor/bootstrap-5.2.1/bootstrap.min.js"; path = bootstrap521js; }
# Bootstrap 4.5 — backwards compatibility (source maps)
{ name = "vendor/bootstrap.min.css.map"; path = bootstrap45cssmap; }
{ name = "vendor/bootstrap.min.js.map"; path = bootstrap45jsmap; }
# Select2 (develop branch with jQuery 4 support)
{ name = "vendor/select2.min.js"; path = select2js; }
{ name = "vendor/select2.min.css"; path = select2css; }
])
];
};
schema-compiler = pkgs.ghc.ihp-schema-compiler;
ssc = pkgs.ghc.ihp-ssc;
migrate = pkgs.ghc.ihp-migrate;
datasync-typescript = pkgs.ghc.ihp-datasync-typescript;
ihp-new = pkgs.callPackage ./ihp-new/default.nix {};
ihp-sitemap = pkgs.ghc.ihp-sitemap;
ihp-datasync = pkgs.ghc.ihp-datasync;
ihp-typed-sql = pkgs.ghc.ihp-typed-sql;
ihp-pglistener = pkgs.ghc.ihp-pglistener;
ihp-job-dashboard = pkgs.ghc.ihp-job-dashboard;
wai-asset-path = pkgs.ghc.wai-asset-path;
wai-flash-messages = pkgs.ghc.wai-flash-messages;
wai-early-return = pkgs.ghc.wai-early-return;
ihp-imagemagick = pkgs.ghc.ihp-imagemagick;
ihp-hspec = pkgs.ghc.ihp-hspec;
ihp-welcome = pkgs.ghc.ihp-welcome;
ihp-mail = pkgs.ghc.ihp-mail;
run-script = pkgs.stdenv.mkDerivation {
pname = "run-script";
version = "1.0.0";
src = ./ihp-ide/exe/IHP/CLI/run-script;
dontUnpack = true;
installPhase = ''
mkdir -p $out/bin
cp $src $out/bin/run-script
chmod +x $out/bin/run-script
'';
};
guide =
let
# node_modules derivation built from yarn.lock + package.json.
# Replaces the removed `mkYarnModules` (yarn2nix) with the standard
# `fetchYarnDeps` + `yarnConfigHook` pipeline from nixpkgs.
node-modules = pkgs.stdenv.mkDerivation {
pname = "guide-node_modules";
version = "1.0.0";
src = pkgs.runCommand "guide-yarn-src" {} ''
mkdir -p $out
cp ${./Guide/package.json} $out/package.json
cp ${./Guide/yarn.lock} $out/yarn.lock
'';
yarnOfflineCache = pkgs.fetchYarnDeps {
yarnLock = ./Guide/yarn.lock;
hash = "sha256-Alr/Bh3T7Bqvs+HgB9a2l730SNnfKGUPPK23SVlUSt0=";
};
nativeBuildInputs = [ pkgs.nodejs pkgs.yarn pkgs.yarnConfigHook ];
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r node_modules $out/
runHook postInstall
'';
};
in
pkgs.stdenv.mkDerivation {
name = "ihp-guide";
src = ./Guide;
nativeBuildInputs = with pkgs; [ haskellPackages.mmark-cli pkgs.esbuild ];
buildPhase = ''
# build HTML from all *.markdown using the template
for f in *.markdown; do
out_html="''${f%.markdown}.html"
mmark -i "$f" -o "$out_html" \
--template layout.html \
--ext-skylighting --ext-ghc-highlighter \
--ext-punctuation --ext-toc 2-6
done
cp ${node-modules}/node_modules/bootstrap/dist/css/bootstrap.min.css bootstrap.css
cp ${node-modules}/node_modules/instantclick/dist/instantclick.min.js instantclick.js
# build search.js via esbuild
NODE_PATH=${node-modules}/node_modules \
${pkgs.esbuild}/bin/esbuild search.jsx \
--bundle \
--preserve-symlinks \
--minify-whitespace \
--define:process.env.NODE_ENV=\"production\" \
--minify \
--legal-comments=none \
--outfile=search.js
'';
installPhase = ''
mkdir -p $out
cp -r *.html *.css *.js images $out/
'';
LOCALE_ARCHIVE = pkgs.lib.optionalString pkgs.stdenv.isLinux "${pkgs.glibcLocales}/lib/locale/locale-archive";
LANG = "en_US.UTF-8";
allowedReferences = [];
};
reference =
let
hackageHtmlLocationFlag = "--html-location='https://hackage.haskell.org/package/$pkgid/docs'";
withHackageLinks = package: pkgs.haskell.lib.overrideCabal package (old: {
haddockFlags = (old.haddockFlags or []) ++ [ hackageHtmlLocationFlag ];
});
# Subpackages whose Haddock should be merged into the reference docs.
# Order matters: ihp-with-docs MUST be first so its index.html /
# doc-index-*.html / linuwial.css / quick-jump.js win on conflicts.
# Subpackages contribute their unique IHP-*.html module pages.
docPackages = with pkgs.ghc; map withHackageLinks [
ihp-with-docs
ihp-pglistener
ihp-router
ihp-mail
ihp-modal
ihp-ssc
# ihp-hsx ships with `doHaddock = false` in its default.nix
# (multi-library cabal makes the default haddock build messy).
# Re-enable it here so IHP-HSX-QQ.html etc. land in api-docs.
(pkgs.haskell.lib.overrideCabal ihp-hsx (old: { doHaddock = true; }))
ihp-pagehead
ihp-job-dashboard
ihp-imagemagick
ihp-typed-sql
];
in
pkgs.stdenv.mkDerivation {
name = "ihp-reference";
src = self;
nativeBuildInputs = docPackages ++ [ pkgs.perl ];
buildPhase = ''
mkdir -p haddock-build
# Merge each package's Haddock html dir into haddock-build/.
# cp -rn ("recursive, no clobber") = first-writer-wins, so the
# core ihp-with-docs index/css/js stay authoritative.
for src in ${lib.concatMapStringsSep " " (p: p.doc.outPath or "") (lib.filter (p: p ? doc) docPackages)}; do
for html_dir in "$src"/share/doc/*/html; do
if [ -d "$html_dir" ]; then
cp -rn "$html_dir"/. haddock-build/ 2>/dev/null || true
fi
done
done
chmod -R u+w haddock-build
cd haddock-build
# Add favicon
find . -type f \( -iname "*.html" \) -exec sed -i 's#<head>#<head><link rel="shortcut icon" type="image\/x-icon" href="https:\/\/ihp.digitallyinduced.com\/ihp-logo.svg"\/>#g' '{}' +
# Add ihp-haddock.css
cp ../ihp-haddock.css ihp-haddock.css
find . -type f \( -iname "*.html" \) -exec sed -i 's#<\/head>#<link href="ihp-haddock.css" rel="stylesheet"/><\/head>#g' '{}' +
# Haddock's --html-location keeps prerequisite package links
# stable. After merging IHP subpackage docs into one directory,
# link sibling package references to the local merged pages.
#
find . -type f \( -iname "*.html" \) -exec perl -0pi -e '
s{href="https://hackage\.haskell\.org/package/[^"/]+/docs/([^"#?]+(?:#[^"]*)?)"}{
my ($target) = ($1);
my ($page) = split /#/, $target, 2;
(-e $page) ? qq{href="$target"} : $&
}ge;
' '{}' +
# Link title to index
find . -type f \( -iname "*.html" \) -exec sed -i 's#<span class=\"caption\">IHP Api Reference</span>#<a href=\"index.html\" class=\"caption\"><img src=\"https://ihp.digitallyinduced.com/Guide/images/ihp-logo-readme.svg\"/>IHP Api Reference</a>#g' '{}' +
cp -R . $out
'';
# allowedReferences = [];
};
# DataSync TypeScript SDK: build + tests + typecheck.
# Replaces the removed `mkYarnPackage` (yarn2nix) with the standard
# `fetchYarnDeps` + `yarnConfigHook` pipeline from nixpkgs.
datasync-js = pkgs.stdenv.mkDerivation {
pname = "datasync-js";
version = "0.1.0";
src = let filter = inputs.nix-filter.lib; in filter {
root = "${self}/ihp-datasync/data/DataSync";
};
yarnOfflineCache = pkgs.fetchYarnDeps {
yarnLock = ./ihp-datasync/data/DataSync/yarn.lock;
hash = "sha256-D9pLOT4afe8M29nKgJyNZhCj0KlF6X8ZQ0e8RZZsVsY=";
};
nativeBuildInputs = [ pkgs.nodejs pkgs.yarn pkgs.yarnConfigHook ];
buildPhase = ''
runHook preBuild
yarn --offline run build
yarn --offline run test
yarn --offline run typecheck
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r . $out/
runHook postInstall
'';
};
# The IHP boilerplate's Makefile depends on an IHP env var that contains
# the Makefile.dist (ihp-ide) and several JS and CSS files (ihp)
ihp-env-var-backwards-compat =
pkgs.symlinkJoin {
name = "ihp-env-var-backwards-compat";
paths = [
("${self}/ihp-ide/data/lib/IHP")
("${self}/ihp-ide/data")
("${self}/ihp/data")
];
# The Makefile references $(IHP)/static/vendor/bootstrap.min.css etc.
# These vendor files (bootstrap, jquery, select2) are fetched via Nix
# in ihp-static, not in the ihp cabal data-files.
postBuild = ''
for f in ${config.packages.ihp-static}/vendor/*; do
ln -sf "$f" "$out/static/vendor/$(basename "$f")" 2>/dev/null || true
done
# Backwards compat: old Makefiles reference popper.min.js
ln -sf "$out/static/vendor/popper-2.11.6.min.js" "$out/static/vendor/popper.min.js" 2>/dev/null || true
'';
};
};
};
}