forked from IntersectMBO/cardano-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
356 lines (331 loc) · 14.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
{
description = "Cardano Node";
inputs = {
# IMPORTANT: report any change to nixpkgs channel in nix/default.nix:
nixpkgs.follows = "haskellNix/nixpkgs-2105";
hostNixpkgs.follows = "nixpkgs";
haskellNix = {
url = "github:input-output-hk/haskell.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
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;
};
membench = {
url = "github:input-output-hk/cardano-memory-benchmark";
inputs.cardano-node-measured.follows = "/";
inputs.cardano-node-process.follows = "/";
inputs.cardano-node-snapshot.url = "github:input-output-hk/cardano-node/7f00e3ea5a61609e19eeeee4af35241571efdf5c";
inputs.nixpkgs.follows = "nixpkgs";
};
# 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";
plutus-example = {
url = "github:input-output-hk/cardano-node/1.33.0";
flake = false;
};
};
outputs = { self, nixpkgs, hostNixpkgs, utils, haskellNix, iohkNix, membench, plutus-example, ... }@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;
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)
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-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-example {
inherit (project.pkgs) system;
gitrev = plutus-example.rev;
}).haskellPackages.plutus-example.components.exes) plutus-example;
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;
projectExes = flatten (haskellLib.collectComponents' "exes" projectPackages) // (with hsPkgsWithPassthru; {
inherit (ouroboros-consensus-byron.components.exes) db-converter;
inherit (ouroboros-consensus-cardano.components.exes) db-analyser;
inherit (bech32.components.exes) bech32;
} // lib.optionalAttrs hostPlatform.isUnix {
inherit (network-mux.components.exes) cardano-ping;
});
};
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;
}).appendModule customConfig.haskellNix // {
profiled = profiledProject;
asserted = assertedProject;
eventlogged = eventloggedProject;
};
inherit (mkPackages project) projectPackages projectExes profiledProject assertedProject eventloggedProject;
shell = import ./shell.nix { inherit pkgs customConfig; };
devShells = {
inherit (shell) devops;
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;
});
packages = exes
# Linux only packages:
// optionalAttrs (system == "x86_64-linux") rec {
"dockerImage/node" = pkgs.dockerImage;
"dockerImage/submit-api" = pkgs.submitApiDockerImage;
membenches = membench.outputs.packages.x86_64-linux.batch-report;
snapshot = membench.outputs.packages.x86_64-linux.snapshot;
workbench-smoke-test = pkgs.clusterNix.smoke-test { profileName = "smoke-loaded-alzo"; };
}
# 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;
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;
};
};
};
}
);
in
builtins.removeAttrs flake [ "systemHydraJobs" ] // {
hydraJobs =
let
jobs = lib.foldl' lib.mergeAttrs { } (lib.attrValues flake.systemHydraJobs);
nonRequiredPaths = map lib.hasPrefix [ ];
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 = 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) ++ [
cardano-deployment
build-version
];
};
});
overlay = final: prev: {
cardanoNodeProject = flake.project.${final.system};
cardanoNodePackages = mkCardanoNodePackages final.cardanoNodeProject;
inherit (final.cardanoNodePackages) cardano-node cardano-cli cardano-submit-api bech32;
};
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});
};
};
};
}