forked from IntersectMBO/cardano-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
482 lines (441 loc) · 18.4 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
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
{
description = "Cardano Node";
nixConfig = {
extra-substituters = ["https://cache.iog.io"];
extra-trusted-public-keys = ["hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="];
};
inputs = {
# IMPORTANT: report any change to nixpkgs channel in nix/default.nix:
nixpkgs.follows = "haskellNix/nixpkgs-unstable";
hostNixpkgs.follows = "nixpkgs";
hackageNix = {
url = "github:input-output-hk/hackage.nix";
flake = false;
};
nixTools = {
url = "github:input-output-hk/nix-tools";
flake = false;
};
haskellNix = {
url = "github:input-output-hk/haskell.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.hackage.follows = "hackageNix";
};
CHaP = {
url = "github:input-output-hk/cardano-haskell-packages?ref=repo";
flake = false;
};
utils.url = "github:numtide/flake-utils";
iohkNix = {
url = "github:input-output-hk/iohk-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-compat = {
url = "github:input-output-hk/flake-compat/fixes";
flake = false;
};
plutus-apps = {
url = "github:input-output-hk/plutus-apps";
flake = false;
};
# Custom user config (default: empty), eg.:
# { outputs = {...}: {
# # Cutomize listeming port of node scripts:
# nixosModules.cardano-node = {
# services.cardano-node.port = 3002;
# };
# };
customConfig.url = "github:input-output-hk/empty-flake";
node-measured = {
url = "github:input-output-hk/cardano-node";
};
node-snapshot = {
url = "github:input-output-hk/cardano-node/7f00e3ea5a61609e19eeeee4af35241571efdf5c";
};
node-process = {
url = "github:input-output-hk/cardano-node";
flake = false;
};
## This pin is to prevent workbench-produced geneses being regenerated each time the node is bumped.
cardano-node-workbench = {
url = "github:input-output-hk/cardano-node/ed9932c52aaa535b71f72a5b4cc0cecb3344a5a3";
# This is to avoid circular import (TODO: remove this workbench pin entirely using materialization):
inputs.membench.url = "github:input-output-hk/empty-flake";
};
cardano-mainnet-mirror.url = "github:input-output-hk/cardano-mainnet-mirror/nix";
tullia = {
url = "github:input-output-hk/tullia";
inputs.nixpkgs.follows = "nixpkgs";
};
nix2container.url = "github:nlewo/nix2container";
};
outputs =
{ self
, nixpkgs
, hostNixpkgs
, utils
, haskellNix
, CHaP
, iohkNix
, plutus-apps
, cardano-mainnet-mirror
, node-snapshot
, node-measured
, node-process
, cardano-node-workbench
, tullia
, nix2container
, ...
}@input:
let
inherit (nixpkgs) lib;
inherit (lib) head systems mapAttrs recursiveUpdate mkDefault
getAttrs optionalAttrs nameValuePair attrNames;
inherit (utils.lib) eachSystem mkApp flattenTree;
inherit (iohkNix.lib) prefixNamesWith;
removeRecurse = lib.filterAttrsRecursive (n: _: n != "recurseForDerivations");
flatten = attrs: lib.foldl' (acc: a: if (lib.isAttrs a) then acc // (removeAttrs a [ "recurseForDerivations" ]) else acc) { } (lib.attrValues attrs);
supportedSystems = import ./nix/supported-systems.nix;
defaultSystem = head supportedSystems;
customConfig = recursiveUpdate
(import ./nix/custom-config.nix customConfig)
input.customConfig;
overlays = [
haskellNix.overlay
iohkNix.overlays.haskell-nix-extra
iohkNix.overlays.crypto
iohkNix.overlays.cardano-lib
iohkNix.overlays.utils
(final: prev: {
inherit customConfig nix2container;
gitrev = final.customConfig.gitrev or self.rev or "0000000000000000000000000000000000000000";
commonLib = lib
// iohkNix.lib
// final.cardanoLib
// import ./nix/svclib.nix { inherit (final) pkgs; };
})
(import ./nix/pkgs.nix)
(import ./nix/workbench/membench-overlay.nix
{
inherit
lib
input
cardano-mainnet-mirror
node-snapshot node-measured node-process;
customConfig = customConfig.membench;
})
self.overlay
];
projectPackagesExes = import ./nix/project-packages-exes.nix;
mkPackages = project:
let
inherit (project.pkgs.stdenv) hostPlatform;
inherit (project.pkgs.haskell-nix) haskellLib;
profiledProject = project.appendModule {
modules = [{
enableLibraryProfiling = true;
packages.cardano-node.components.exes.cardano-node.enableProfiling = true;
packages.tx-generator.components.exes.tx-generator.enableProfiling = true;
packages.locli.components.exes.locli.enableProfiling = true;
}];
};
assertedProject = project.appendModule {
modules = [{
packages = lib.genAttrs [
"ouroboros-consensus"
"ouroboros-consensus-cardano"
"ouroboros-consensus-cardano-tools"
"ouroboros-consensus-byron"
"ouroboros-consensus-shelley"
"ouroboros-network"
"network-mux"
]
(name: { flags.asserts = true; });
}];
};
eventloggedProject = project.appendModule
{
modules = [{
packages = lib.genAttrs [ "cardano-node" ]
(name: { configureFlags = [ "--ghc-option=-eventlog" ]; });
}];
};
inherit ((import plutus-apps {
inherit (project.pkgs) system;
}).plutus-apps.haskell.packages.plutus-example.components.exes) plutus-example;
pinned-workbench =
cardano-node-workbench.workbench.${project.pkgs.system};
hsPkgsWithPassthru = lib.mapAttrsRecursiveCond (v: !(lib.isDerivation v))
(path: value:
if (lib.isAttrs value) then
lib.recursiveUpdate value
{
passthru = {
profiled = lib.getAttrFromPath path profiledProject.hsPkgs;
asserted = lib.getAttrFromPath path assertedProject.hsPkgs;
eventlogged = lib.getAttrFromPath path eventloggedProject.hsPkgs;
};
} else value)
project.hsPkgs;
projectPackages = lib.mapAttrs (n: _: hsPkgsWithPassthru.${n}) projectPackagesExes;
in
{
inherit projectPackages profiledProject assertedProject eventloggedProject;
inherit pinned-workbench;
projectExes = flatten (haskellLib.collectComponents' "exes" projectPackages) // (with hsPkgsWithPassthru; {
inherit (ouroboros-consensus-byron.components.exes) db-converter;
inherit (ouroboros-consensus-cardano-tools.components.exes) db-analyser db-synthesizer;
inherit (bech32.components.exes) bech32;
} // lib.optionalAttrs hostPlatform.isUnix {
inherit (network-mux.components.exes) cardano-ping;
inherit plutus-example;
});
};
mkCardanoNodePackages = project: (mkPackages project).projectExes // {
inherit (project.pkgs) cardanoLib;
};
flake = eachSystem supportedSystems (system:
let
pkgs = import nixpkgs {
inherit system overlays;
inherit (haskellNix) config;
};
inherit (pkgs.haskell-nix) haskellLib;
inherit (haskellLib) collectChecks' collectComponents';
inherit (pkgs.commonLib) eachEnv environments mkSupervisordCluster;
inherit (project.pkgs.stdenv) hostPlatform;
project = (import ./nix/haskell.nix {
inherit (pkgs) haskell-nix gitrev;
inherit projectPackagesExes;
inputMap = {
"https://input-output-hk.github.io/cardano-haskell-packages" = CHaP;
};
}).appendModule customConfig.haskellNix // {
profiled = profiledProject;
asserted = assertedProject;
eventlogged = eventloggedProject;
};
inherit (mkPackages project) projectPackages projectExes profiledProject assertedProject eventloggedProject pinned-workbench;
shell = import ./shell.nix { inherit pkgs customConfig cardano-mainnet-mirror; };
devShells = {
inherit (shell) devops workbench-shell;
cluster = shell;
profiled = project.profiled.shell;
};
devShell = shell.dev;
# NixOS tests run a node and submit-api and validate it listens
nixosTests = import ./nix/nixos/tests {
inherit pkgs;
};
checks = flattenTree (collectChecks' projectPackages) //
# Linux only checks:
(optionalAttrs hostPlatform.isLinux (
prefixNamesWith "nixosTests/" (mapAttrs (_: v: v.${system} or v) nixosTests)
))
# checks run on default system only;
// (optionalAttrs (system == defaultSystem) {
hlint = pkgs.callPackage pkgs.hlintCheck {
inherit (project.args) src;
};
});
exes = projectExes // {
inherit (pkgs) cabalProjectRegenerate checkCabalProject;
"dockerImages/push" = import ./.buildkite/docker-build-push.nix {
hostPkgs = import hostNixpkgs { inherit system; };
inherit (pkgs) dockerImage submitApiDockerImage;
};
"dockerImage/node/load" = pkgs.writeShellScript "load-docker-image" ''
docker load -i ${pkgs.dockerImage} $@
'';
"dockerImage/submit-api/load" = pkgs.writeShellScript "load-submit-docker-image" ''
docker load -i ${pkgs.submitApiDockerImage} $@
'';
} // flattenTree (pkgs.scripts // {
# `tests` are the test suites which have been built.
tests = collectComponents' "tests" projectPackages;
# `benchmarks` (only built, not run).
benchmarks = collectComponents' "benchmarks" projectPackages;
});
inherit (pkgs) workbench all-profiles-json workbench-runner;
packages =
exes
# Linux only packages:
// optionalAttrs (system == "x86_64-linux") rec {
"dockerImage/node" = pkgs.dockerImage;
"dockerImage/submit-api" = pkgs.submitApiDockerImage;
## TODO: drop external membench, once we bump 'node-snapshot'
# snapshot = membench.outputs.packages.x86_64-linux.snapshot;
# membenches = pkgs.membench-node-this-5.batch-report;
## This is a very light profile, no caching&pinning needed.
workbench-ci-test =
(pkgs.workbench-runner
{
profileName = "ci-test-bage";
backendName = "supervisor";
## Not required, as long as it's fast.
# workbench = pinned-workbench;
cardano-node-rev =
if __hasAttr "rev" self
then self.rev
else throw "Cannot get git revision of 'cardano-node', unclean checkout?";
}).profile-run {};
all-profiles-json = pkgs.all-profiles-json;
}
# Add checks to be able to build them individually
// (prefixNamesWith "checks/" checks);
apps = lib.mapAttrs (n: p: { type = "app"; program = p.exePath or (if (p.executable or false) then "${p}" else "${p}/bin/${p.name or n}"); }) exes;
in
{
inherit environments packages checks apps project;
legacyPackages = pkgs;
# Built by `nix build .`
defaultPackage = packages.cardano-node;
# Run by `nix run .`
defaultApp = apps.cardano-node;
# This is used by `nix develop .` to open a devShell
inherit devShell devShells;
# The parametrisable workbench.
inherit workbench;
systemHydraJobs = optionalAttrs (system == "x86_64-linux")
{
linux = {
native = packages // {
shells = devShells // {
default = devShell;
};
internal = {
roots.project = project.roots;
plan-nix.project = project.plan-nix;
};
profiled = lib.genAttrs [ "cardano-node" "tx-generator" "locli" ] (n:
packages.${n}.passthru.profiled
);
asserted = lib.genAttrs [ "cardano-node" ] (n:
packages.${n}.passthru.asserted
);
};
musl =
let
muslProject = project.projectCross.musl64;
inherit (mkPackages muslProject) projectPackages projectExes;
in
projectExes // {
cardano-node-linux = import ./nix/binary-release.nix {
inherit pkgs;
inherit (exes.cardano-node.identifier) version;
platform = "linux";
exes = lib.collect lib.isDerivation projectExes;
};
internal.roots.project = muslProject.roots;
};
windows =
let
windowsProject = project.projectCross.mingwW64;
inherit (mkPackages windowsProject) projectPackages projectExes;
in
projectExes
// (removeRecurse {
checks = collectChecks' projectPackages;
tests = collectComponents' "tests" projectPackages;
benchmarks = collectComponents' "benchmarks" projectPackages;
cardano-node-win64 = import ./nix/binary-release.nix {
inherit pkgs;
inherit (exes.cardano-node.identifier) version;
platform = "win64";
exes = lib.collect lib.isDerivation projectExes;
};
internal.roots.project = windowsProject.roots;
});
};
} // optionalAttrs (system == "x86_64-darwin") {
macos = lib.filterAttrs
(n: _:
# only build docker images once on linux:
!(lib.hasPrefix "dockerImage" n))
packages // {
cardano-node-macos = import ./nix/binary-release.nix {
inherit pkgs;
inherit (exes.cardano-node.identifier) version;
platform = "macos";
exes = lib.collect lib.isDerivation projectExes;
};
shells = removeAttrs devShells [ "profiled" ] // {
default = devShell;
};
internal = {
roots.project = project.roots;
plan-nix.project = project.plan-nix;
};
};
};
} //
tullia.fromSimple system (import ./nix/tullia.nix self system)
);
makeRequired = isPr: jobs: extra:
let
nonRequiredPaths = map lib.hasPrefix
([ "macos." ] ++
[ "linux.windows.checks.cardano-tracer.cardano-tracer-test" ] ++
lib.optional isPr "linux.native.membenches");
in with self.legacyPackages.${defaultSystem};
releaseTools.aggregate {
name = "github-required";
meta.description = "All jobs required to pass CI";
constituents = lib.collect lib.isDerivation
(lib.mapAttrsRecursiveCond (v: !(lib.isDerivation v))
(path: value:
let stringPath = lib.concatStringsSep "." path; in if lib.isAttrs value && (lib.any (p: p stringPath) nonRequiredPaths) then { } else value)
jobs) ++ extra;
};
makeOsRequired = isPr: jobs: {
linux = jobs.linux // {
required = makeRequired isPr jobs.linux [];
};
macos = jobs.macos // {
required = makeRequired isPr jobs.macos [];
};
};
hydraJobs =
let
jobs = lib.foldl' lib.mergeAttrs { } (lib.attrValues flake.systemHydraJobs);
in
jobs // (with self.legacyPackages.${defaultSystem}; rec {
cardano-deployment = cardanoLib.mkConfigHtml { inherit (cardanoLib.environments) mainnet testnet; };
build-version = writeText "version.json" (builtins.toJSON {
inherit (self) lastModified lastModifiedDate narHash outPath shortRev rev;
});
required = makeRequired false jobs [ cardano-deployment build-version ];
}) // makeOsRequired false jobs;
hydraJobsPr =
let
nonPrJobs = map lib.hasPrefix [
"linux.native.membenches"
];
jobs = lib.mapAttrsRecursiveCond (v: !(lib.isDerivation v))
(path: value:
let stringPath = lib.concatStringsSep "." path; in if lib.isAttrs value && (lib.any (p: p stringPath) nonPrJobs) then { } else value)
hydraJobs;
in
jobs // {
required = makeRequired true jobs [ hydraJobs.cardano-deployment hydraJobs.build-version ];
} // makeOsRequired true jobs;
in
builtins.removeAttrs flake [ "systemHydraJobs" ] // {
inherit hydraJobs hydraJobsPr;
overlay = final: prev: {
cardanoNodeProject = flake.project.${final.system};
cardanoNodePackages = mkCardanoNodePackages final.cardanoNodeProject;
inherit (final.cardanoNodePackages) cardano-node cardano-cli cardano-submit-api cardano-tracer bech32 locli plutus-example db-analyser;
};
nixosModules = {
cardano-node = { pkgs, lib, ... }: {
imports = [ ./nix/nixos/cardano-node-service.nix ];
services.cardano-node.cardanoNodePackages = lib.mkDefault (mkCardanoNodePackages flake.project.${pkgs.system});
};
cardano-submit-api = { pkgs, lib, ... }: {
imports = [ ./nix/nixos/cardano-submit-api-service.nix ];
services.cardano-submit-api.cardanoNodePackages = lib.mkDefault (mkCardanoNodePackages flake.project.${pkgs.system});
};
};
};
}