forked from input-output-hk/cardano-sl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
307 lines (261 loc) · 11.3 KB
/
default.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
########################################################################
# default.nix -- The top-level nix build file for cardano-sl.
#
# This file defines an attribute set of cardano-sl packages.
#
# It contains:
#
# - pkgs -- the nixpkgs set that the build is based on.
# - haskellPackages.* -- the package set based on stackage
# - haskellPackages.ghc -- the compiler
# - cardanoPackages -- just cardano packages
#
# - acceptanceTests -- tests which need network access to connect to
# the actual relay nodes.
#
# - dockerImages -- for exchanges and developers who like docker
# Build these and `docker load -i` the resulting
# file.
# - mainnet
# - staging
# - testnet
#
# - connectScripts -- builds a script which starts a wallet. Run the
# resulting script.
# - mainnet.wallet -- connect a wallet to mainnet
# - mainnet.explorer -- explorer node connected to testnet
# - staging.* -- connect scripts for staging
# - testnet.* -- connect scripts for testnet
#
# Other files:
# - shell.nix - dev environment, used by nix-shell / nix run.
# - release.nix - the Hydra jobset.
# - lib.nix - the localLib common functions.
# - nix/* - other nix code modules used by this file.
#
# See also:
# - docs/how-to/build-cardano-sl-and-daedalus-from-source-code.md
# - docs/nix.md
#
########################################################################
let
localLib = import ./lib.nix;
in
{ system ? builtins.currentSystem
, crossSystem ? null
, config ? {} # The nixpkgs configuration file
# Use a pinned version nixpkgs.
, pkgs ? localLib.importPkgs { inherit system crossSystem config; }
# SHA1 hash which will be embedded in binaries
, gitrev ? localLib.commitIdFromGitRepo ./.git
# This is set by CI
, buildId ? null
# Disable running of tests for all cardano-sl packages.
, forceDontCheck ? false
# Enable profiling for all haskell packages.
# Profiling slows down performance by 50% so we don't enable it by default.
, enableProfiling ? false
# Keeps the debug information for all haskell packages.
, enableDebugging ? false
# Build (but don't run) benchmarks for all cardano-sl packages.
, enableBenchmarks ? false
# Overrides all nix derivations to add build timing information in
# their build output.
, enablePhaseMetrics ? true
# Disables optimization in the build for all cardano-sl packages.
, fasterBuild ? false
# Whether local options in ./custom-wallet-config.nix should apply to
# the wallet connect script build.
, allowCustomConfig ? true
# Makes the demo wallet/cluster/connect scripts use "stack exec"
# instead of running the nix-built executables.
, useStackBinaries ? false
}:
with pkgs.lib;
let
src = localLib.cleanSourceTree ./.;
packages = self: ({
inherit pkgs;
# This is the stackage LTS plus overrides, plus the cardano-sl
# packages.
haskellPackages = self.callPackage ./nix/haskell-packages.nix {
inherit forceDontCheck enableProfiling enablePhaseMetrics
enableBenchmarks fasterBuild enableDebugging;
};
# fixme: I would like to have these attributes at the top-level,
# but am getting problems with infinite recursion. Help me!
cardanoPackages = localLib.getCardanoPackages self.justStaticExecutablesGitRev self.haskellPackages;
# fixme: this is just for CI so should probably only be in release.nix
all-cardano-sl = pkgs.buildEnv {
name = "all-cardano-sl";
paths = attrValues self.cardanoPackages;
ignoreCollisions = true;
};
####################################################################
# Frontends
# The explorer frontend, built with Purescript.
cardano-sl-explorer-frontend = self.callPackage ./explorer/frontend {
cardano-sl-explorer = self.cardanoPackages.cardano-sl-explorer-static;
};
# A demo/development frontend for the faucet API. Override this
# derivation to customize URLs, etc.
cardano-sl-faucet-frontend = self.callPackage ./faucet/frontend { };
# Backwards compat for iohk-ops.
makeFaucetFrontend = self.cardano-sl-faucet-frontend;
####################################################################
# Report Server
cardano-report-server-static = self.justStaticExecutablesGitRev self.cardano-report-server;
####################################################################
# Daedalus wallet
# Packages all the configuration required for running a node.
cardano-sl-config = self.callPackage ./nix/cardano-sl-config.nix { };
# Provides the edge node (wallet), tools, and configuration
# required for Daedalus.
daedalus-bridge = self.callPackage ./nix/daedalus-bridge.nix {
cardano-sl-node = self.cardanoPackages.cardano-sl-node-static;
cardano-sl-tools = self.cardanoPackages.cardano-sl-tools-static;
cardano-wallet = self.cardanoPackages.cardano-wallet-static;
};
####################################################################
# Docker images
dockerImages = let
build = args: self.callPackage ./nix/docker.nix ({
inherit (self.cardanoPackages) cardano-sl-node-static;
} // args);
makeDockerImage = { environment, ...}:
build { inherit environment; } // {
wallet = build { inherit environment; type = "wallet"; };
explorer = build { inherit environment; type = "explorer"; };
node = build { inherit environment; type = "node"; };
};
in localLib.forEnvironments makeDockerImage;
####################################################################
# Tests
tests = {
shellcheck = self.callPackage ./scripts/test/shellcheck.nix { inherit src; };
hlint = self.callPackage ./scripts/test/hlint.nix { inherit src; };
stylishHaskell = self.callPackage ./scripts/test/stylish.nix { inherit (self.haskellPackages) stylish-haskell; inherit src; };
swaggerSchemaValidation = self.callPackage ./scripts/test/wallet/swaggerSchemaValidation.nix {
inherit (self.cardanoPackages) cardano-wallet;
};
yamlValidation = self.callPackage ./scripts/test/yamlValidation.nix {
inherit (self) haskellPackages; inherit (localLib) runHaskell;
};
};
# Currently the only acceptance tests here are to sync the wallet
# against mainnet and testnet.
acceptanceTests = let
acceptanceTest = args: self.callPackage ./scripts/test/acceptance ({
inherit (self.cardanoPackages)
cardano-sl-tools
cardano-wallet;
} // args);
mkTest = { environment, ...}: {
full = acceptanceTest { inherit environment; resume = false; };
quick = acceptanceTest { inherit environment; resume = true; };
};
in localLib.forEnvironments mkTest;
####################################################################
## Connect scripts and demo cluster
# A function to connect a wallet to a network.
# The args parameter is an attrset for parameters applied to
# ./scripts/launch/connect-to-cluster/default.nix
connect = let
walletConfigFile = ./custom-wallet-config.nix;
walletConfig = if allowCustomConfig
then (if builtins.pathExists walletConfigFile then import walletConfigFile else {})
else {};
in
args: self.callPackage ./scripts/launch/connect-to-cluster (args // {
inherit (self.cardanoPackages)
cardano-wallet-static
cardano-sl-explorer-static
cardano-sl-tools-static;
inherit useStackBinaries;
} // walletConfig);
# Connect scripts for each network
connectScripts = localLib.forEnvironments ({ environment, ... }: {
wallet = self.connect { inherit environment; };
explorer = self.connect { inherit environment; executable = "explorer"; };
});
# Produces a script which starts a cluster of core nodes and a
# relay, then connects an edge node (wallet) to it.
demoCluster = self.callPackage ./scripts/launch/demo-cluster {
inherit useStackBinaries;
inherit (self.cardanoPackages)
cardano-sl cardano-sl-cluster cardano-wallet;
};
####################################################################
# Build tools
# Utility which removes all but the statically linked executables
# of a haskell package, and stamps them with the git revision.
justStaticExecutablesGitRev = self.callPackage ./scripts/set-git-rev {
inherit (self.haskellPackages) ghc;
inherit gitrev;
};
# Tool for generating ./pkgs/default.nix
# stack2nix = self.callPackage ./nix/stack2nix.nix { };
# TODO: go back to using our own build of stack2nix, rather than
# the version from nixpkgs. The following PRs need to be fixed:
# https://github.com/input-output-hk/stack2nix/pull/128
# https://github.com/input-output-hk/stack2nix/pull/135
inherit (pkgs) stack2nix;
validateJson = self.callPackage ./tools/src/validate-json {};
# Add a shell attributes so these can be built and cached by Hydra.
shells = {
cabal = import ./shell.nix { inherit system config pkgs; iohkPkgs = self; };
stack = import ./nix/stack-shell.nix { inherit system config pkgs; iohkPkgs = self; };
};
####################################################################
# Version info
inherit (self.haskellPackages.cardano-sl) version;
inherit gitrev;
}
# fixme: Temporary fix for hydra evaluation
// { inherit (self.cardanoPackages)
cardano-sl
cardano-sl-auxx
cardano-sl-script-runner
cardano-sl-chain
cardano-sl-cluster
cardano-sl-core
cardano-sl-crypto
cardano-sl-db
cardano-sl-explorer
cardano-sl-explorer-static
cardano-sl-generator
cardano-sl-infra
cardano-sl-networking
cardano-sl-node-static
cardano-sl-tools
cardano-sl-tools-post-mortem
cardano-sl-util
cardano-sl-x509
cardano-wallet
cardano-wallet-static;
inherit (self.haskellPackages)
cardano-report-server; }
# nix-tools setup
// (with builtins; with pkgs.lib; let nix-tools = import ./nix/pkgs.nix { nixpkgs = _: pkgs; }; in
{
nix-tools = { _raw = nix-tools; }
# some shorthands
// { libs = mapAttrs (k: v: if v.components ? "library"
then v.components.library
else null) nix-tools; }
// { exes = mapAttrs (k: v: if length (attrValues v.components.exes) > 0
then (if pkgs.stdenv.targetPlatform.isWindows then pkgs.copyJoin else pkgs.symlinkJoin)
{ name = "${k}-exes"; paths = attrValues v.components.exes; }
else null) nix-tools; }
// { tests = mapAttrs (k: v: if length (attrValues v.components.tests) > 0
then v.components.tests
else null) nix-tools; }
// { benchmarks = mapAttrs (k: v: if length (attrValues v.components.benchmarks) > 0
then v.components.benchmarks
else null) nix-tools; }
;
})
);
in
# The top-level package set
pkgs.lib.makeScope pkgs.newScope packages