forked from cardano-foundation/cardano-wallet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
396 lines (368 loc) · 16.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
{
description = "Cardano Wallet";
############################################################################
#
# Cardano Wallet Flake Nix build
#
# Nix Flake support instruction: https://nixos.wiki/wiki/Flakes
#
# 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-core.unit
# - cardano-wallet.integration
# - etc (layout is PACKAGE.COMPONENT)
# - checks - attrset of test-suite results
# - cardano-wallet-core.unit
# - cardano-wallet.integration
# - etc
# - benchmarks - attret of benchmark executables
# - cardano-wallet-core.db
# - cardano-wallet.latency
# - etc
# - dockerImage - tarball of the docker image
#
# Other documentation:
# https://input-output-hk.github.io/cardano-wallet/dev/Building#nix-build
#
############################################################################
inputs = {
nixpkgs.follows = "haskellNix/nixpkgs-2111";
hostNixpkgs.follows = "nixpkgs";
haskellNix = {
url = "github:input-output-hk/haskell.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
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/fixes";
flake = false;
};
customConfig.url = "github:input-output-hk/empty-flake";
emanote = {
url = "github:srid/emanote";
};
ema = {
url = "github:srid/ema";
};
};
outputs = { self, nixpkgs, hostNixpkgs, flake-utils, haskellNix, iohkNix, customConfig, emanote, ... }:
let
inherit (nixpkgs) lib;
config = import ./nix/config.nix lib customConfig;
inherit (flake-utils.lib) eachSystem mkApp flattenTree;
removeRecurse = lib.filterAttrsRecursive (n: _: n != "recurseForDerivations");
inherit (iohkNix.lib) evalService;
supportedSystems = import ./nix/supported-systems.nix;
defaultSystem = lib.head supportedSystems;
overlay = final: prev: {
cardanoWalletHaskellProject = self.legacyPackages.${final.system};
inherit (final.cardanoWalletHaskellProject.hsPkgs.cardano-wallet.components.exes) cardano-wallet;
};
nixosModule = { pkgs, lib, ... }: {
imports = [ ./nix/nixos/cardano-wallet-service.nix ];
services.cardano-node.package = lib.mkDefault self.defaultPackage.${pkgs.system};
};
nixosModules.cardano-wallet = nixosModule;
# Which exes should be put in the release archives.
releaseContents = jobs: map (exe: jobs.${exe}) [
"cardano-wallet"
"bech32"
"cardano-address"
"cardano-cli"
"cardano-node"
];
mkRequiredJob = hydraJobs:
let
nonRequiredPaths = map lib.hasPrefix [ ];
in
self.legacyPackages.${lib.head supportedSystems}.pkgs.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.any (p: p stringPath) nonRequiredPaths) then { } else value)
hydraJobs);
};
mkHydraJobs = systemsJobs:
let hydraJobs = lib.foldl' lib.mergeAttrs { } (lib.attrValues systemsJobs);
in
hydraJobs // {
required = mkRequiredJob hydraJobs;
};
systems = eachSystem supportedSystems
(system:
let
pkgs = import nixpkgs {
inherit system;
inherit (haskellNix) config;
overlays = [
haskellNix.overlay
iohkNix.overlays.utils
iohkNix.overlays.crypto
iohkNix.overlays.haskell-nix-extra
iohkNix.overlays.cardano-lib
# Haskell build tools
(import ./nix/overlays/build-tools.nix)
# Cardano deployments
(import ./nix/overlays/cardano-deployments.nix)
# Other packages overlay
(import ./nix/overlays/pkgs.nix)
# Our own utils (cardanoWalletLib)
(import ./nix/overlays/common-lib.nix)
overlay
];
};
inherit (pkgs.stdenv) buildPlatform;
inherit (pkgs.haskell-nix.haskellLib)
isProjectPackage
collectComponents
collectChecks;
project = (import ./nix/haskell.nix pkgs.haskell-nix).appendModule [{
gitrev =
if config.gitrev != null
then config.gitrev
else self.rev or "0000000000000000000000000000000000000000";
}
config.haskellNix];
profiledProject = project.appendModule { profiling = true; };
hydraProject = project.appendModule ({ pkgs, ... }: {
# FIXME: Set in the CI so we don't make mistakes.
#checkMaterialization = true;
# Don't build benchmarks for musl.
buildBenchmarks = !pkgs.stdenv.hostPlatform.isMusl;
});
hydraProjectBors = hydraProject.appendModule ({ pkgs, ... }: {
# Sets the anti-cache cookie only when building a jobset for bors.
cacheTestFailures = false;
});
hydraProjectPr = hydraProject.appendModule ({ pkgs, ... }: {
# Don't run integration tests on PR jobsets. Note that
# the master branch jobset will just re-use the cached Bors
# staging build and test results.
doIntegrationCheck = false;
});
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.components.exes.cardano-wallet;
backend = self.cardano-node;
};
# Local test cluster and mock metadata server
inherit (project.hsPkgs.cardano-wallet.components.exes)
local-cluster
mock-token-metadata-server;
# Adrestia tool belt
inherit (project.hsPkgs.bech32.components.exes) bech32;
inherit (project.hsPkgs.cardano-addresses-cli.components.exes) cardano-address;
# Cardano
inherit (project.hsPkgs.cardano-cli.components.exes) cardano-cli;
cardano-node = project.hsPkgs.cardano-node.components.exes.cardano-node // {
deployments = pkgs.cardano-node-deployments;
};
# 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 = removeRecurse (collectComponents "tests" isProjectPackage coveredProject.hsPkgs);
# `checks` are the result of executing the tests.
checks = removeRecurse (collectChecks isProjectPackage coveredProject.hsPkgs);
# `benchmarks` are only built, not run.
benchmarks = 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 {
profiled = (project.appendModule { profiling = true; }).shell;
cabal = import ./nix/cabal-shell.nix {
haskellProject = project;
inherit (config) withCabalCache ghcVersion;
};
stack = cabal.overrideAttrs (old: {
name = "cardano-wallet-stack-env";
nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.stack ];
# Build environment setup copied from
# <nixpkgs/pkgs/development/haskell-modules/generic-stack-builder.nix>
STACK_PLATFORM_VARIANT = "nix";
STACK_IN_NIX_SHELL = 1;
STACK_IN_NIX_EXTRA_ARGS = config.stackExtraArgs;
});
docs = pkgs.mkShell {
name = "cardano-wallet-docs";
nativeBuildInputs = [ emanote.defaultPackage.${system} pkgs.yq ];
# allow building the shell so that it can be cached in hydra
phases = [ "installPhase" ];
installPhase = "echo $nativeBuildInputs > $out";
};
};
mkSystemHydraJobs = hydraProject: lib.optionalAttrs buildPlatform.isLinux
rec {
linux = {
# Don't run tests on linux native, because they are run for linux musl.
native = removeAttrs (mkPackages hydraProject) [ "checks" "testCoverageReport" ] // {
scripts = mkScripts hydraProject;
shells = (mkDevShells hydraProject) // {
default = hydraProject.shell;
};
internal.roots = {
project = hydraProject.roots;
iohk-nix-utils = pkgs.iohk-nix-utils.roots;
};
nixosTests = import ./nix/nixos/tests {
inherit pkgs;
project = hydraProject;
};
};
musl =
let
project = hydraProject.projectCross.musl64;
packages = mkPackages project;
in
packages // {
dockerImage = mkDockerImage packages;
internal.roots = {
project = project.roots;
};
cardano-wallet-linux64 = import ./nix/release-package.nix {
inherit pkgs;
exes = releaseContents packages;
platform = "linux64";
format = "tar.gz";
};
};
windows =
let
project = hydraProject.projectCross.mingwW64;
# Remove the test coverage report - only generate that for Linux musl.
windowsPackages = removeAttrs (mkPackages project) [ "testCoverageReport" ];
in
windowsPackages // {
cardano-wallet-win64 = import ./nix/release-package.nix {
inherit pkgs;
exes = releaseContents windowsPackages;
platform = "win64";
format = "zip";
};
# This is used for testing the build on windows.
cardano-wallet-tests-win64 = import ./nix/windows-testing-bundle.nix {
inherit pkgs;
cardano-wallet = windowsPackages.cardano-wallet;
cardano-node = windowsPackages.cardano-node;
cardano-cli = windowsPackages.cardano-cli;
tests = lib.collect lib.isDerivation windowsPackages.tests;
benchmarks = lib.collect lib.isDerivation windowsPackages.benchmarks;
};
internal.roots = {
project = project.roots;
};
};
};
} // (lib.optionalAttrs buildPlatform.isMacOS {
macos.intel = lib.optionalAttrs buildPlatform.isx86_64 (let
packages = mkPackages hydraProject;
in packages // {
cardano-wallet-macos-intel = import ./nix/release-package.nix {
inherit pkgs;
exes = releaseContents packages;
platform = "macos-intel";
format = "tar.gz";
};
shells = mkDevShells hydraProject // {
default = hydraProject.shell;
};
scripts = mkScripts hydraProject;
internal.roots = {
project = hydraProject.roots;
iohk-nix-utils = pkgs.iohk-nix-utils.roots;
};
});
macos.silicon = lib.optionalAttrs buildPlatform.isAarch64 (let
packages = mkPackages hydraProject;
in packages // {
cardano-wallet-macos-silicon = import ./nix/release-package.nix {
inherit pkgs;
exes = releaseContents packages;
platform = "macos-silicon";
format = "tar.gz";
};
shells = mkDevShells hydraProject // {
default = hydraProject.shell;
};
scripts = mkScripts hydraProject;
internal.roots = {
project = hydraProject.roots;
iohk-nix-utils = pkgs.iohk-nix-utils.roots;
};
});
});
in
rec {
legacyPackages = project;
# Built by `nix build .`
defaultPackage = packages.cardano-wallet;
# Run by `nix run .`
defaultApp = apps.cardano-wallet;
packages = mkPackages project // mkScripts project // rec {
dockerImage = mkDockerImage (mkPackages project.projectCross.musl64);
pushDockerImage = import ./.buildkite/docker-build-push.nix {
hostPkgs = import hostNixpkgs { inherit system; };
inherit dockerImage;
inherit (config) dockerHubRepoName;
};
inherit (pkgs) sha256map-regenerate checkStackProject;
inherit (project.stack-nix.passthru) generateMaterialized;
buildToolsGenerateMaterialized = pkgs.haskell-build-tools.regenerateMaterialized;
iohkNixGenerateMaterialized = pkgs.iohk-nix-utils.regenerateMaterialized;
} // (lib.optionalAttrs buildPlatform.isLinux {
nixosTests = import ./nix/nixos/tests {
inherit pkgs project;
};
});
apps = lib.mapAttrs (n: p: { type = "app"; program = p.exePath or "${p}/bin/${p.name or n}"; }) packages;
devShell = project.shell;
devShells = mkDevShells project;
systemHydraJobs = mkSystemHydraJobs hydraProject;
systemHydraJobsPr = mkSystemHydraJobs hydraProjectPr;
systemHydraJobsBors = mkSystemHydraJobs hydraProjectBors;
});
in
lib.recursiveUpdate (removeAttrs systems [ "systemHydraJobs" "systemHydraJobsPr" "systemHydraJobsBors" ])
{
inherit overlay nixosModule nixosModules;
hydraJobs = mkHydraJobs systems.systemHydraJobs;
hydraJobsPr = mkHydraJobs systems.systemHydraJobsPr;
hydraJobsBors = mkHydraJobs systems.systemHydraJobsBors;
}
;
}