-
Notifications
You must be signed in to change notification settings - Fork 217
/
flake.nix
491 lines (457 loc) · 18.3 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
483
484
485
486
487
488
489
490
491
{
description = "Cardano Wallet";
############################################################################
#
# Cardano Wallet Flake Nix build
#
# See ./nix/README.md for more documentation about this file.
#
# Derivation attributes of this file can be build with "nix build .#<attribute>"
# Discover attribute names using tab-completion in your shell.
#
# Interesting top-level attributes:
#
# - cardano-wallet - cli executable
# - tests - attrset of test-suite executables
# - cardano-wallet.unit
# - cardano-wallet.integration
# - etc (layout is PACKAGE.COMPONENT)
# - checks - attrset of test-suite results
# - cardano-wallet.unit
# - cardano-wallet.integration
# - etc
# - benchmarks - attret of benchmark executables
# - cardano-wallet.db
# - cardano-wallet.latency
# - etc
# - dockerImage - tarball of the docker image
#
############################################################################
############################################################################
# Continuous Integration (CI)
#
# This flake contains a few outputs useful for continous integration.
# These outputs come in two flavors:
#
# outputs.packages."<system>".ci.* - build a test, benchmark, …
# outputs.apps."<system>".ci.* - run a test, benchmark, …
#
# For building, say all tests, use `nix build`:
#
# nix build .#ci.tests.all
#
# For running, say the unit tests use `nix run`:
#
# nix run .#ci.tests.unit
#
# (Running an item will typically also build it if it has not been built
# in the nix store already.)
#
#
# The CI-related outputs are
#
# - outputs.packages."<system>".ci.
# - tests
# - all - build all test executables
# - benchmarks
# - all - build all benchmarks
# - restore - build individual benchmark
# - …
# - artifacts - artifacts by platform
# - linux64.release
# - win64
# - release
# - tests - bundle of executables for testing on Windows
# - macos-intel.release
# - macos-silicon.release
# - dockerImage
# - outputs.apps."<system>".ci.
# - tests
# - unit - run the unit tests on this system
# - integration - run the integration tests on this system
# - benchmarks
# - restore
# - …
#
# Recommended granularity:
#
# after each commit:
# on x86_64-linux:
# nix build .#ci.tests.all
# nix build .#ci.benchmarks.all
# nix build .#ci.artifacts.linux64.release
# nix build .#ci.artifacts.win64.release
# nix build .#ci.artifacts.win64.tests
#
# nix run .#ci.tests.unit
#
# before each pull request merge:
# on each supported system:
# nix build .#ci.benchmarks.all
# nix build .#ci.tests.all
#
# nix run .#ci.tests.unit
# nix run .#ci.tests.integration
#
# nightly:
# on x86_64-linux:
# nix build .#ci.artifacts.dockerImage
#
# nix run .#ci.benchmarks.restore
# nix run .#ci.benchmarks.…
#
# on x65_64-darwin: (macos)
# nix build .#ci.artifacts.win64.release
#
############################################################################
############################################################################
# TODO Continuous Integration (CI)
#
# Make the flake.nix file *itself* part of continuous integration,
# i.e. check that `devShells`, `scripts` or `nixosTests` evalute and build
# correctly.
############################################################################
inputs = {
nixpkgs-unstable.url = "nixpkgs/nixos-unstable";
nixpkgs.follows = "haskellNix/nixpkgs-unstable";
hostNixpkgs.follows = "nixpkgs";
CHaP = {
url = "github:intersectmbo/cardano-haskell-packages?ref=repo";
flake = false;
};
haskellNix = {
url = "github:input-output-hk/haskell.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.hackage.follows = "hackage";
};
hackage = {
url = "github:input-output-hk/hackage.nix";
flake = false;
};
flake-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";
flake = false;
};
customConfig.url = "github:input-output-hk/empty-flake";
cardano-node-runtime.url = "github:IntersectMBO/cardano-node?ref=10.1.3";
};
outputs = { self, nixpkgs, nixpkgs-unstable, hostNixpkgs, flake-utils,
haskellNix, iohkNix, CHaP, customConfig, cardano-node-runtime,
... }:
let
# Import libraries
lib = import ./nix/lib.nix nixpkgs.lib;
config = import ./nix/config.nix nixpkgs.lib customConfig;
inherit (flake-utils.lib) eachSystem mkApp flattenTree;
inherit (iohkNix.lib) evalService;
# Definitions
supportedSystems = import ./nix/supported-systems.nix;
overlay = final: prev: {
cardanoWalletHaskellProject = self.legacyPackages.${final.system};
inherit (final.cardanoWalletHaskellProject.hsPkgs.cardano-wallet-exe.components.exes) cardano-wallet;
haskell-nix = prev.haskell-nix // {
extraPkgconfigMappings = prev.haskell-nix.extraPkgconfigMappings // {
# String pkgconfig-depends names are mapped to lists of Nixpkgs
# package names
"libblst" = [ "blst" ];
};
};
};
nixosModule = { pkgs, lib, ... }: {
imports = [ ./nix/nixos/cardano-wallet-service.nix ];
services.cardano-node.package = lib.mkDefault self.packages.${pkgs.system}.cardano-node;
};
nixosModules.cardano-wallet = nixosModule;
# Define flake outputs for a particular system.
mkOutputs = system:
let
pkgs = import nixpkgs {
inherit system;
inherit (haskellNix) config;
overlays = [
iohkNix.overlays.utils
iohkNix.overlays.crypto
iohkNix.overlays.cardano-lib
haskellNix.overlay
iohkNix.overlays.haskell-nix-extra
# Cardano deployments
(import ./nix/overlays/cardano-deployments.nix)
# Our own utils (cardanoWalletLib)
(import ./nix/overlays/common-lib.nix)
overlay
];
};
inherit (pkgs.stdenv) buildPlatform;
inherit (pkgs.haskell-nix.haskellLib)
isProjectPackage
collectComponents
collectChecks
check;
nodePackages = cardano-node-runtime.packages.${system};
nodeProject = cardano-node-runtime.project.${system};
nodeConfigs = lib.fileset.toSource {
root = ./configs;
fileset = ./configs;
};
walletProject = (import ./nix/haskell.nix
CHaP
pkgs.haskell-nix
nixpkgs-unstable.legacyPackages.${system}
nodePackages
).appendModule [{
gitrev =
if config.gitrev != null
then config.gitrev
else self.rev or "0000000000000000000000000000000000000000";
}
config.haskellNix];
mkPackages = project:
let
coveredProject = project.appendModule { coverage = true; };
self = {
# Cardano wallet
cardano-wallet = import ./nix/release-build.nix {
inherit pkgs;
exe = project.hsPkgs.cardano-wallet-exe.components.exes.cardano-wallet;
backend = self.cardano-node;
};
# Local test cluster and mock metadata server
inherit (project.hsPkgs.cardano-wallet.components.exes) mock-token-metadata-server;
inherit (project.hsPkgs.cardano-wallet-benchmarks.components.exes) benchmark-history;
inherit (project.hsPkgs.local-cluster.components.exes) local-cluster;
inherit (project.hsPkgs.cardano-wallet-integration.components.exes) integration-exe;
inherit (project.hsPkgs.local-cluster.components.exes) test-local-cluster-exe;
# Adrestia tool belt
inherit (project.hsPkgs.bech32.components.exes) bech32;
inherit (project.hsPkgs.cardano-addresses-cli.components.exes) cardano-address;
# Cardano
cardano-cli = nodeProject.hsPkgs.cardano-cli.components.exes.cardano-cli;
cardano-node = nodeProject.hsPkgs.cardano-node.components.exes.cardano-node // {
deployments = pkgs.cardano-node-deployments;
};
cardano-wallet-e2e = project.hsPkgs.cardano-wallet-e2e.components.exes.wallet-e2e;
# Provide db-converter, so daedalus can ship it without needing to
# pin an ouroborus-network rev.
inherit (project.hsPkgs.ouroboros-consensus-byron.components.exes) db-converter;
# Combined project coverage report
testCoverageReport = coveredProject.projectCoverageReport;
# `tests` are the test suites which have been built.
tests =
lib.removeRecurse (collectComponents "tests" isProjectPackage coveredProject.hsPkgs);
# `checks` are the result of executing the tests.
checks = lib.removeRecurse (collectChecks isProjectPackage coveredProject.hsPkgs);
# `benchmarks` are only built, not run.
benchmarks =
lib.removeRecurse (collectComponents "benchmarks" isProjectPackage project.hsPkgs);
};
in
self;
# nix run .#<network>/wallet
mkScripts = project: flattenTree (import ./nix/scripts.nix {
inherit project evalService;
customConfigs = [ config ];
});
# See the imported file for how to use the docker build.
mkDockerImage = packages: pkgs.callPackage ./nix/docker.nix {
exes = with packages; [ cardano-wallet local-cluster ];
base = with packages; [
bech32
cardano-address
cardano-cli
cardano-node
(pkgs.linkFarm "docker-config-layer" [{ name = "config"; path = pkgs.cardano-node-deployments; }])
];
};
mkDevShells = project: rec {
default = project.shell;
profiled = (project.appendModule { profiling = true; }).shell;
docs = pkgs.mkShell {
name = "cardano-wallet-docs";
nativeBuildInputs = [ pkgs.mdbook pkgs.mdbook-mermaid pkgs.mdbook-admonish];
# allow building the shell so that it can be cached
phases = [ "installPhase" ];
installPhase = "echo $nativeBuildInputs > $out";
};
};
# One ${system} can cross-compile artifacts for other platforms.
mkReleaseArtifacts = project:
let # compiling with musl gives us a statically linked executable
linuxPackages = mkPackages project.projectCross.musl64;
linuxReleaseExes = [
linuxPackages.cardano-wallet
linuxPackages.bech32
linuxPackages.cardano-address
cardano-node-runtime.hydraJobs.x86_64-linux.musl.cardano-cli
cardano-node-runtime.hydraJobs.x86_64-linux.musl.cardano-node
];
# Which exes should be put in the release archives.
checkReleaseContents = jobs: map (exe: jobs.${exe}) [
"cardano-wallet"
"bech32"
"cardano-address"
"cardano-cli"
"cardano-node"
];
in lib.optionalAttrs buildPlatform.isLinux {
linux64.release =
import ./nix/release-package.nix {
inherit pkgs nodeConfigs;
walletLib = lib;
exes = linuxReleaseExes;
platform = "linux64";
format = "tar.gz";
};
win64 =
let
# windows is cross-compiled from linux
windowsPackages =
mkPackages project.projectCross.mingwW64 // {
cardano-cli =
cardano-node-runtime.hydraJobs.x86_64-linux.windows.cardano-cli;
cardano-node =
cardano-node-runtime.hydraJobs.x86_64-linux.windows.cardano-node;
};
in {
release = import ./nix/release-package.nix {
inherit pkgs nodeConfigs;
walletLib = lib;
exes = [
windowsPackages.cardano-wallet
windowsPackages.bech32
windowsPackages.cardano-address
windowsPackages.cardano-cli
windowsPackages.cardano-node
];
platform = "win64";
format = "zip";
};
# Testing on Windows is done using a collection of executables.
tests = import ./nix/windows-testing-bundle.nix {
inherit pkgs;
cardano-wallet = windowsPackages.cardano-wallet;
cardano-cli = windowsPackages.cardano-cli;
cardano-node = windowsPackages.cardano-node;
tests = lib.collect lib.isDerivation windowsPackages.tests;
benchmarks = lib.collect lib.isDerivation windowsPackages.benchmarks;
};
};
}
# macos is never cross-compiled
// lib.optionalAttrs buildPlatform.isMacOS {
macos-intel = lib.optionalAttrs buildPlatform.isx86_64 {
release = import ./nix/release-package.nix {
inherit pkgs nodeConfigs;
walletLib = lib;
exes = let macOsPkgs = mkPackages project; in [
macOsPkgs.cardano-wallet
macOsPkgs.bech32
macOsPkgs.cardano-address
nodePackages.cardano-cli
nodePackages.cardano-node
];
platform = "macos-intel";
format = "tar.gz";
};
};
macos-silicon = lib.optionalAttrs buildPlatform.isAarch64 {
release = import ./nix/release-package.nix {
inherit pkgs nodeConfigs;
walletLib = lib;
exes = let macOsPkgs = mkPackages project; in [
macOsPkgs.cardano-wallet
macOsPkgs.bech32
macOsPkgs.cardano-address
nodePackages.cardano-cli
nodePackages.cardano-node
];
platform = "macos-silicon";
format = "tar.gz";
};
};
};
in
rec {
legacyPackages = walletProject;
# Built by `nix build .`
defaultPackage = packages.cardano-wallet;
# Run by `nix run .`
defaultApp = apps.cardano-wallet;
packages =
mkPackages walletProject
// mkScripts walletProject
// rec {
dockerImage =
mkDockerImage (mkPackages walletProject.projectCross.musl64);
pushDockerImage = import ./.buildkite/docker-build-push.nix {
hostPkgs = import hostNixpkgs { inherit system; };
inherit dockerImage;
inherit (config) dockerHubRepoName;
};
} // (lib.optionalAttrs buildPlatform.isLinux {
nixosTests = import ./nix/nixos/tests {
inherit pkgs;
project = walletProject;
};
}) // {
# Continuous integration builds
ci.tests.all = pkgs.releaseTools.aggregate {
name = "cardano-wallet-tests";
meta.description = "Build (all) tests";
constituents =
lib.collect lib.isDerivation packages.tests;
};
ci.benchmarks =
let
collectedBenchmarks =
lib.concatMapAttrs (_n: v: v) packages.benchmarks;
in
collectedBenchmarks // {
all = pkgs.releaseTools.aggregate {
name = "cardano-wallet-benchmarks";
meta.description = "Build all benchmarks";
constituents =
lib.collect lib.isDerivation collectedBenchmarks;
};
};
ci.artifacts = mkReleaseArtifacts walletProject // {
dockerImage = packages.dockerImage;
};
};
# Heinrich: I don't quite understand the 'checks' attribute. See also
# https://www.reddit.com/r/NixOS/comments/x5cjmz/comment/in0qqm6/?utm_source=share&utm_medium=web2x&context=3
checks = packages.checks;
mkApp = name: pkg: {
type = "app";
program = pkg.exePath or "${pkg}/bin/${pkg.name or name}";
};
apps = lib.mapAttrs mkApp packages;
devShells = mkDevShells walletProject;
ci.tests.run.unit = pkgs.releaseTools.aggregate
{
name = "tests.run.unit";
meta.description = "Run unit tests";
constituents =
lib.collect lib.isDerivation
(lib.keepUnitChecks packages.checks);
};
ci.tests.run.integration = pkgs.releaseTools.aggregate
{
name = "tests.run.integration";
meta.description = "Run integration tests";
constituents =
lib.collect lib.isDerivation
(lib.keepIntegrationChecks packages.checks);
};
};
systems = eachSystem supportedSystems mkOutputs;
in
lib.recursiveUpdate systems {
inherit overlay nixosModule nixosModules;
}
;
}