-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathflake.nix
More file actions
388 lines (367 loc) · 13.4 KB
/
Copy pathflake.nix
File metadata and controls
388 lines (367 loc) · 13.4 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
{
description = "hyperbole overlay, development and hyperbole-demo";
nixConfig = {
extra-substituters = [
"https://hyperbole.cachix.org"
];
extra-trusted-public-keys = [
"hyperbole.cachix.org-1:9Pl9dJXuJrAxGkrG8WNQ/hlO9rKt9b5IPksG7y78UGQ="
];
};
inputs = {
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
nix-filter.url = "github:numtide/nix-filter/main";
atomic-css.url = "github:seanhess/atomic-css";
};
outputs =
{
self,
nixpkgs,
nix-filter,
flake-utils,
pre-commit-hooks,
atomic-css,
}:
let
packageName = "hyperbole";
demoName = "hyperbole-demo";
src = nix-filter.lib {
root = ./.;
include = [
"src"
"client/dist"
"client/util/live-reload.js"
"test"
./${packageName}.cabal
./cabal.project
./package.yaml
./fourmolu.yaml
./README.md
./CHANGELOG.md
./LICENSE
];
};
overlay = final: prev: {
overriddenHaskellPackages = {
ghc9124 = (prev.overriddenHaskellPackages.ghc9124 or prev.haskell.packages.ghc9124).override (old: {
overrides = prev.lib.composeExtensions (old.overrides or (_: _: { })) (
hfinal: hprev: {
"${packageName}" = hfinal.callCabal2nix packageName src { };
# `atomic-css` upstream overlay does not support `ghc912x` currently
atomic-css = hfinal.callCabal2nix "atomic-css" atomic-css { };
}
);
});
ghc9103 = (prev.overriddenHaskellPackages.ghc9103 or prev.haskell.packages.ghc9103).override (old: {
overrides = prev.lib.composeExtensions (old.overrides or (_: _: { })) (
hfinal: hprev: {
"${packageName}" = hfinal.callCabal2nix packageName src { };
# `atomic-css` upstream overlay does not support `ghc910x` currently
atomic-css = hfinal.callCabal2nix "atomic-css" atomic-css { };
}
);
});
ghc984 = (prev.overriddenHaskellPackages.ghc984 or prev.haskell.packages.ghc984).override (old: {
overrides = prev.lib.composeExtensions (old.overrides or (_: _: { })) (
hfinal: hprev: {
"${packageName}" = hfinal.callCabal2nix packageName src { };
}
);
});
ghc967 = (prev.overriddenHaskellPackages.ghc967 or prev.haskell.packages.ghc967).override (old: {
overrides = prev.lib.composeExtensions (old.overrides or (_: _: { })) (
hfinal: hprev: {
"${packageName}" = hfinal.callCabal2nix packageName src { };
# Tests require `skeletest`, which needs to be pinned as follow:
# `nixpkgs` ships `skeletest_0_3_7` for `ghc967`, BUT skeletest >= 0.1.1 dropped ghc9.6.x,
# That's why we use `0.1.0` here available at Hackage (not with `nixpkgs`).
skeletest = hfinal.callHackage "skeletest" "0.1.0" { };
# `skeletest` `0.1.0` constraints `Diff < 1.0`
Diff = hfinal.callHackage "Diff" "0.5" { };
}
);
});
};
};
in
{
overlays.default = nixpkgs.lib.composeExtensions atomic-css.overlays.default overlay;
}
// flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
# DON'T include symlink `docs` (demo/docs -> ../docs)
# as Nix (or `nix-filter`) can't handle it properly and will error instead
# `docs` will be merged in `demo-docs-src` later on
demo-src = nix-filter.lib {
root = ./demo;
include = [
"App"
"Example"
(nix-filter.lib.matchExt "hs")
./demo/demo.cabal
];
};
docs-hs-src = nix-filter.lib {
root = ./docs;
include = [ (nix-filter.lib.matchExt "hs") ];
};
docs-md-src = nix-filter.lib {
root = ./docs;
include = [ (nix-filter.lib.matchExt "md") ];
};
oauth2-src = nix-filter.lib {
root = ./hyperbole-oauth2;
include = [
"src"
(nix-filter.lib.matchExt "hs")
./hyperbole-oauth2/hyperbole-oauth2.cabal
./hyperbole-oauth2/README.md # required by `extra-doc-files` in `hyperbole-oauth2.cabal`
];
};
# Merges filtered `demo` + `docs` sources into `$out`.
# Needed to solve `demo/docs` -> `../docs` symlink issue Nix has before.
# Name it "demo" to have a store path `/nix/store/<hash>-demo`.
# That's what `demo-with-docs-src` expects to resolve source files. Check `demo/App/Docs/Snippet.hs` -> `localFile`
demo-with-docs-src = pkgs.runCommand "demo" { } ''
mkdir -p $out/docs
cp -rL ${demo-src}/. $out/
cp -rL ${docs-md-src}/. $out/docs/
'';
# Merges `src` + `demo` + `docs` (.hs only) for building the library.
hyperbole-with-demo-docs-src = pkgs.runCommand packageName { } ''
mkdir -p $out/demo $out/docs
cp -rL ${src}/. $out/
cp -rL ${demo-src}/. $out/demo/
cp -rL ${docs-hs-src}/. $out/docs/
'';
# Minimal sources for building `docgen` executable only.
# Same `packageName` ("hyperbole") since it's an executable of the library itself.
# and to match the `name` in `hyperbole.cabal`.
docgen-exe-src = pkgs.runCommand packageName { } ''
mkdir -p $out/docs
cp ${./hyperbole.cabal} $out/hyperbole.cabal
cp ${./LICENSE} $out/LICENSE
cp ${docs-hs-src}/Docgen.hs $out/docs/Docgen.hs
'';
ghcVersions = [
"967"
"984"
"9103"
"9124"
];
ghcPkgs = builtins.listToAttrs (
map (ghcVer: {
name = "ghc${ghcVer}";
value = (
pkgs.overriddenHaskellPackages."ghc${ghcVer}".extend (
hfinal: hprev:
let
# Build `docgen` executable (but no library)
# to break the circular dependency being a preprocessor AND executable of SAME package
docgen-exe = pkgs.haskell.lib.justStaticExecutables (
pkgs.haskell.lib.dontCheck (
pkgs.haskell.lib.overrideCabal (hfinal.callCabal2nix packageName docgen-exe-src { }) (_: {
buildTarget = "docgen";
})
)
);
in
{
# `docgen-exe` needs to be available in PATH for ALL build phases (incl. `haddock`).
${packageName} = pkgs.haskell.lib.addBuildTool (hfinal.callCabal2nix packageName
hyperbole-with-demo-docs-src
{ }
) docgen-exe;
# `docgen` is needed in `shell` and `checks` (search for `.docgen` to see it).
docgen = hfinal.${packageName};
${demoName} = hfinal.callCabal2nix demoName demo-with-docs-src { };
hyperbole-oauth2 = hfinal.callCabal2nix "hyperbole-oauth2" oauth2-src { };
}
)
);
}) ghcVersions
);
pre-commit = pre-commit-hooks.lib.${system}.run {
src = src;
excludes = [
"^client/node_modules/"
"^client/dist/"
];
hooks = {
hlint.enable = true;
fourmolu.enable = true;
hpack.enable = false;
nixfmt.enable = true;
flake-checker = {
enable = true;
args = [ "--no-telemetry" ];
};
check-merge-conflicts.enable = true;
# `oxlint` uses the lockfile-pinned version here (`pre-commit-hooks` may provide a different one)
oxlint = {
enable = true;
name = "oxlint";
entry = "npm run --prefix client lint";
language = "system";
files = "^client/";
pass_filenames = false;
};
# `oxfmt` uses the lockfile-pinned version here (`pre-commit-hooks` may provide a different one)
oxfmt = {
enable = true;
name = "oxfmt (check)";
entry = "npm run --prefix client fmt";
language = "system";
files = "^client/";
pass_filenames = false;
};
};
};
shellCommon = version: {
shellHook = ''
${pre-commit.shellHook}
# `oxlint`/`oxfmt` hooks require lockfile-pinned binaries from `node_modules`
if [ ! -d "client/node_modules" ]; then
npm install --prefix client
fi
'';
buildInputs = with pkgs.haskell.packages."ghc${version}"; [
pkgs.nodejs_24
cabal-install
haskell-language-server
hlint
fourmolu
fast-tags
ghcid
pkgs.ghciwatch
pkgs.hpack
# `docgen` is required by `hls`, also by running `nix flake check` to resolve `type docgen`
(pkgs.haskell.lib.justStaticExecutables ghcPkgs."ghc${version}".docgen)
];
withHoogle = true;
doBenchmark = true;
CABAL_CONFIG = "/dev/null";
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ pkgs.zlib ];
};
exe =
version:
pkgs.haskell.lib.overrideCabal
(pkgs.haskell.lib.justStaticExecutables self.packages.${system}."ghc${version}-${demoName}")
(drv: {
# Added due to an issue building on macOS only
postInstall = ''
${drv.postInstall or ""}
echo "Contents of $out/bin:"
ls -la $out/bin
echo remove-references-to -t ${ghcPkgs."ghc${version}".warp}
remove-references-to -t ${ghcPkgs."ghc${version}".warp} $out/bin/*
'';
});
docker =
version:
pkgs.dockerTools.buildImage {
name = demoName;
created = "now";
tag = "latest";
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [
pkgs.tree
pkgs.bash
(exe version)
(pkgs.runCommand "static-files" { } ''
mkdir -p $out/demo/static
mkdir -p $out/client/dist
cp -r ${./demo/static}/* $out/demo/static/
cp -r ${./client/dist}/* $out/client/dist
'')
];
pathsToLink = [
"/bin"
"/demo/static"
"/client/dist"
];
};
config = {
Entrypoint = [ "/bin/demo" ];
WorkingDir = "/";
};
};
in
{
# Rest of the output remains the same...
checks = builtins.listToAttrs (
map (version: {
name = "ghc${version}-check-${demoName}";
value = pkgs.runCommand "ghc${version}-check-demo" {
buildInputs = [
(exe version)
# required to resolve `type docgen` in the check script
(pkgs.haskell.lib.justStaticExecutables ghcPkgs."ghc${version}".docgen)
]
++ self.devShells.${system}."ghc${version}-shell".buildInputs;
} "type demo; type docgen; CABAL_CONFIG=/dev/null cabal --dry-run repl; touch $out";
}) ghcVersions
);
apps = {
default = self.apps.${system}."ghc9103-${demoName}";
}
// builtins.listToAttrs (
map (version: {
name = "ghc${version}-${demoName}";
value = {
type = "app";
program = "${exe version}/bin/demo";
};
}) ghcVersions
);
packages = {
default = self.packages.${system}."ghc9103-${packageName}";
docker = self.packages.${system}."ghc9103-docker";
}
// builtins.listToAttrs (
builtins.concatMap (version: [
{
name = "ghc${version}-${demoName}";
value = ghcPkgs."ghc${version}".${demoName};
}
{
name = "ghc${version}-docker";
value = docker version;
}
{
name = "ghc${version}-${packageName}";
value = ghcPkgs."ghc${version}".${packageName};
}
]) ghcVersions
);
devShells = {
default = self.devShells.${system}.ghc9103-shell;
}
// builtins.listToAttrs (
map (version: {
name = "ghc${version}-shell";
value = ghcPkgs."ghc${version}".shellFor (
shellCommon version
// {
packages = p: [
p.${packageName}
p.${demoName}
];
}
);
}) ghcVersions
);
}
);
}