-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathflake.nix
More file actions
387 lines (372 loc) · 14.4 KB
/
flake.nix
File metadata and controls
387 lines (372 loc) · 14.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
{
description = "cardano-api";
inputs = {
hackageNix = {
url = "github:input-output-hk/hackage.nix";
flake = false;
};
haskellNix = {
url = "github:input-output-hk/haskell.nix";
inputs.hackage.follows = "hackageNix";
inputs.nixpkgs.follows = "nixpkgs";
};
# blst fails to build for x86_64-darwin
# nixpkgs.follows = "haskellNix/nixpkgs-unstable";
nixpkgs.url = "github:NixOS/nixpkgs/11cb3517b3af6af300dd6c055aeda73c9bf52c48";
unstable.url = "nixpkgs/nixos-unstable";
iohkNix.url = "github:input-output-hk/iohk-nix";
flake-utils.url = "github:hamishmack/flake-utils/hkm/nested-hydraJobs";
pre-commit-hooks.url = "github:cachix/git-hooks.nix";
incl.url = "github:divnix/incl";
# non-flake nix compatibility
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
CHaP = {
url = "github:intersectmbo/cardano-haskell-packages?ref=repo";
flake = false;
};
hls = {
url = "github:haskell/haskell-language-server/2.13.0.0";
flake = false;
};
cardano-dev.url = "github:input-output-hk/cardano-dev";
# wasm specific inputs
wasm-nixpkgs.follows = "ghc-wasm-meta/nixpkgs";
ghc-wasm-meta.url = "gitlab:haskell-wasm/ghc-wasm-meta?host=gitlab.haskell.org";
};
outputs = inputs: let
supportedSystems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
# see flake `variants` below for alternative compilers
# this is used to build cardano-node on linux, so we test against it
stableCompiler = "ghc967";
# this is our main compiler for development
defaultCompiler = "ghc9122";
# Used for cross compilation for windows.
crossCompilerVersion = defaultCompiler;
# Used for haddock generation (avoids GHC 9.12 tyConStupidTheta panic)
haddockCompiler = "ghc914";
in
inputs.flake-utils.lib.eachSystem supportedSystems (
system: let
# setup our nixpkgs with the haskell.nix overlays, and the iohk-nix
# overlays...
nixpkgs = let
abseilOverlay = final: prev:
prev.lib.optionalAttrs prev.stdenv.hostPlatform.isWindows {
abseil-cpp = prev.abseil-cpp.overrideAttrs (finalAttrs: previousAttrs: {
buildInputs = previousAttrs.buildInputs ++ [prev.pkgs.windows.mingw_w64_pthreads];
});
};
unstableOverlay = final: prev: {
unstable = import inputs.unstable {
inherit system;
inherit (inputs.haskellNix) config;
};
};
in
import inputs.nixpkgs {
overlays = [
unstableOverlay
# iohkNix.overlays.crypto provide libsodium-vrf, libblst and libsecp256k1.
inputs.iohkNix.overlays.crypto
# haskellNix.overlay can be configured by later overlays, so need to come before them.
inputs.haskellNix.overlay
# configure haskell.nix to use iohk-nix crypto librairies.
inputs.iohkNix.overlays.haskell-nix-crypto
abseilOverlay
];
inherit system;
inherit (inputs.haskellNix) config;
};
inherit (nixpkgs) lib;
proto-js-bundle-drv = import ./nix/proto-to-js.nix {pkgs = nixpkgs;};
wasm-typedoc-drv = import ./nix/typedoc.nix {pkgs = nixpkgs;};
pre-commit-check = inputs.pre-commit-hooks.lib.${nixpkgs.system}.run {
src = ./.;
hooks = {
alejandra.enable = true;
cabal-gild = {
enable = true;
entry = let
script = nixpkgs.writeShellScript "precommit-cabal-gild" ''
for file in "$@"; do
cabal-gild --io="$file"
done
'';
in
builtins.toString script;
files = "\\.cabal$";
};
prettify = {
enable = true;
entry = "scripts/githooks/haskell-style-lint";
types = ["haskell"];
};
};
};
# We use cabalProject' to ensure we don't build the plan for
# all systems.
cabalProject = nixpkgs.haskell-nix.cabalProject' ({config, ...}: {
src = ./.;
name = "cardano-api";
compiler-nix-name = lib.mkDefault defaultCompiler;
# we also want cross compilation to windows on linux (and only with default compiler).
crossPlatforms = p:
lib.optional (system == "x86_64-linux" && config.compiler-nix-name == crossCompilerVersion)
p.mingwW64;
# CHaP input map, so we can find CHaP packages (needs to be more
# recent than the index-state we set!). Can be updated with
#
# nix flake lock --update-input CHaP
#
inputMap = {
"https://chap.intersectmbo.org/" = inputs.CHaP;
};
# Also currently needed to make `nix flake lock --update-input CHaP` work.
cabalProjectLocal = ''
repository cardano-haskell-packages-local
url: file:${inputs.CHaP}
secure: True
active-repositories: hackage.haskell.org, cardano-haskell-packages-local
'';
shell.packages = p: [
# Packages in this repo
p.cardano-api
p.cardano-api-gen
# Work around for issue created by our inability to register sublibs.
# This package may need to be built and we need to make sure its dependencies
# are included in `ghc-pkg list` (in particular `compact`)
p.ouroboros-consensus
];
# tools we want in our shell, from hackage
shell.tools =
{
cabal = "3.16.1.0";
}
// lib.optionalAttrs (config.compiler-nix-name == defaultCompiler) {
# tools that work only with default compiler
ghcid = "0.8.9";
cabal-gild = "1.7.0.1";
fourmolu = "0.18.0.0";
proto-lens-protoc = "latest";
haskell-language-server = {
src = inputs.hls;
configureArgs = "--disable-benchmarks --disable-tests";
cabalProjectLocal = ''
allow-newer: haddock-library:base
'';
sha256map."https://github.com/snowleopard/alga"."d4e43fb42db05413459fb2df493361d5a666588a" = "0s1mlnl64wj7pkg3iipv5bb4syy3bhxwqzqv93zqlvkyfn64015i";
};
hlint = "3.10";
};
# and from nixpkgs or other inputs
shell.nativeBuildInputs = with nixpkgs; [
gh
git
jq
yq-go
unstable.actionlint
shellcheck
snappy
protobuf
# buf version must match `.github/workflows/haskell.yml` (buf is
# not backwards-compatible across minor versions for
# `buf generate` output).
unstable.buf
blst
inputs.cardano-dev.packages.${system}.herald
(writeShellScriptBin "haskell-language-server-wrapper" ''exec haskell-language-server "$@"'')
];
# disable Hoogle until someone request it
shell.withHoogle = false;
# Skip cross compilers for the shell
shell.crossPlatforms = _: [];
shell.shellHook = ''
export PATH="${nixpkgs.nix}/bin:$PATH"
${pre-commit-check.shellHook}
export LD_LIBRARY_PATH="${nixpkgs.snappy}/lib:$LD_LIBRARY_PATH"
export PATH="$(git rev-parse --show-toplevel)/scripts/devshell:$PATH"
'';
# package customizations as needed. Where cabal.project is not
# specific enough, or doesn't allow setting these.
modules = [
({...}: {
packages.cardano-api = {
configureFlags = ["--ghc-option=-Werror"];
components = {
tests.cardano-api-golden = {
preCheck = ''
export CREATE_GOLDEN_FILES=1
'';
};
};
};
})
({
pkgs,
config,
...
}: let
generatedExampleFiles = map (f: "cardano-wasm/lib-wrapper/${f}") (builtins.filter (f: lib.strings.hasSuffix ".d.ts" f) (builtins.attrNames (builtins.readDir ./cardano-wasm/lib-wrapper)));
exportWasmPath = "export CARDANO_WASM=${config.hsPkgs.cardano-wasm.components.exes.cardano-wasm}/bin/cardano-wasm${pkgs.stdenv.hostPlatform.extensions.executable}";
in {
packages.cardano-wasm.components.tests.cardano-wasm-golden.preCheck = let
filteredProjectBase = inputs.incl ./. generatedExampleFiles;
in ''
${exportWasmPath}
cp -r ${filteredProjectBase}/* ..
'';
})
{
packages.crypton-x509-system.postPatch = ''
substituteInPlace crypton-x509-system.cabal --replace 'Crypt32' 'crypt32'
'';
}
({
pkgs,
config,
...
}: {
packages =
{
basement.components.library.configureFlags = [
"--hsc2hs-option=--cflag=-Wno-int-conversion"
];
}
// lib.optionalAttrs (config.packages ? proto-lens-protobuf-types) {
proto-lens-protobuf-types.components.library.build-tools = [pkgs.buildPackages.protobuf];
};
})
];
});
# ... and construct a flake from the cabal project
flake = cabalProject.flake (
lib.optionalAttrs (system == "x86_64-linux") {
# on linux, build/test other supported compilers
variants = let
# on windows we're using defaultCompiler only - stableCompiler makes ghc-iserv flaky
osDependentStableCompiler =
if nixpkgs.stdenv.hostPlatform.isWindows
then defaultCompiler
else stableCompiler;
in
lib.genAttrs [osDependentStableCompiler crossCompilerVersion haddockCompiler] (compiler-nix-name: {
inherit compiler-nix-name;
});
}
);
# wasm shell
wasmShell = let
wasm-pkgs = inputs.wasm-nixpkgs.legacyPackages.${system};
wasi-sdk = inputs.ghc-wasm-meta.packages.${system}.wasi-sdk;
wasm = {
libsodium =
wasm-pkgs.callPackage ./nix/libsodium.nix {inherit wasi-sdk;};
secp256k1 = (wasm-pkgs.callPackage ./nix/secp256k1.nix {inherit wasi-sdk;}).overrideAttrs (_: {
src = nixpkgs.secp256k1.src;
});
blst =
(wasm-pkgs.callPackage ./nix/blst.nix {
inherit wasi-sdk;
version = nixpkgs.blst.version;
}).overrideAttrs (_: {
src = nixpkgs.blst.src;
});
};
in
lib.optionalAttrs (system != "x86_64-darwin") {
wasm = wasm-pkgs.mkShell {
packages =
[
wasm-pkgs.pkg-config
wasm-pkgs.curl
wasm-pkgs.git
wasm-pkgs.patch-package
wasm-pkgs.binaryen
inputs.ghc-wasm-meta.packages.${system}.all_9_10
wasm.libsodium
wasm.secp256k1
wasm.blst
]
++ lib.optional (system == "x86_64-linux" || system == "aarch64-linux") wasm-pkgs.envoy-bin;
};
};
playwrightShell = let
playwright-pkgs = inputs.nixpkgs.legacyPackages.${system};
in {
playwright = playwright-pkgs.mkShell {
packages = [
playwright-pkgs.playwright-test
playwright-pkgs.python313Packages.docopt
playwright-pkgs.python313Packages.httpserver
];
};
};
flakeWithWasmShell = nixpkgs.lib.recursiveUpdate flake {
devShells = wasmShell;
hydraJobs = {devShells = wasmShell;};
};
flakeWithPlaywrightShell = nixpkgs.lib.recursiveUpdate flakeWithWasmShell {
devShells = playwrightShell;
hydraJobs = {devShells = playwrightShell;};
};
in
nixpkgs.lib.recursiveUpdate flakeWithPlaywrightShell rec {
project = cabalProject;
# add a required job, that's basically all hydraJobs.
hydraJobs =
nixpkgs.callPackages inputs.iohkNix.utils.ciJobsAggregates
{
ciJobs =
flakeWithPlaywrightShell.hydraJobs
// {
# This ensure hydra send a status for the required job (even if no change other than commit hash)
revision = nixpkgs.writeText "revision" (inputs.self.rev or "dirty");
proto-js-bundle = proto-js-bundle-drv;
wasm-typedoc = wasm-typedoc-drv;
};
}
// {
packages = {
wasm-typedoc = wasm-typedoc-drv;
proto-js-bundle = proto-js-bundle-drv;
};
};
legacyPackages = {
inherit cabalProject nixpkgs;
# also provide hydraJobs through legacyPackages to allow building without system prefix:
inherit hydraJobs;
};
packages = {
proto-js-bundle = proto-js-bundle-drv;
wasm-typedoc = wasm-typedoc-drv;
};
devShells = let
# profiling shell
profilingShell = p: {
# `nix develop .#profiling` (or `.#ghc927.profiling): a shell with profiling enabled
profiling = (p.appendModule {modules = [{enableLibraryProfiling = true;}];}).shell;
};
in
profilingShell cabalProject;
# formatter used by nix fmt
formatter = nixpkgs.alejandra;
}
);
nixConfig = {
extra-substituters = [
"https://cache.iog.io"
];
extra-trusted-public-keys = [
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
];
allow-import-from-derivation = true;
};
}