forked from The-Blockchain-Company/bcc-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.nix
220 lines (197 loc) · 8.29 KB
/
release.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
############################################################################
#
# Hydra release jobset.
#
# The purpose of this file is to select jobs defined in default.nix and map
# them to all supported build platforms.
#
############################################################################
# The project sources
{ bcc-node ? { outPath = ./.; rev = "abcdef"; }
# Function arguments to pass to the project
, projectArgs ? {
inherit sourcesOverride;
config = { allowUnfree = false; inHydra = true; };
gitrev = bcc-node.rev;
}
# The systems that the jobset will be built for.
, supportedSystems ? [ "x86_64-linux" "x86_64-darwin" ]
# The systems used for cross-compiling (default: linux)
, supportedCrossSystems ? [ (builtins.head supportedSystems) ]
# Build for linux
, linuxBuild ? builtins.elem "x86_64-linux" supportedSystems
# Build for macos
, macosBuild ? builtins.elem "x86_64-darwin" supportedSystems
# Cross compilation to Windows is currently only supported on linux.
, windowsBuild ? builtins.elem "x86_64-linux" supportedCrossSystems
# A Hydra option
, scrubJobs ? true
# Dependencies overrides
, sourcesOverride ? {}
# Import pkgs, including TBCO common nix lib
, pkgs ? import ./nix { inherit sourcesOverride; }
}:
with pkgs.lib;
let
linuxRelease = (import pkgs.tbcoNix.release-lib) {
inherit pkgs;
supportedSystems = [ "x86_64-linux" ];
supportedCrossSystems = filter (s: s == "x86_64-linux") supportedCrossSystems;
inherit scrubJobs projectArgs;
packageSet = import bcc-node;
gitrev = bcc-node.rev;
};
macosRelease = (import pkgs.tbcoNix.release-lib) {
inherit pkgs;
supportedSystems = [ "x86_64-darwin" ];
supportedCrossSystems = filter (s: s == "x86_64-darwin") supportedCrossSystems;
inherit scrubJobs projectArgs;
packageSet = import bcc-node;
gitrev = bcc-node.rev;
};
windowsRelease = if (elem "x86_64-linux" supportedCrossSystems) then linuxRelease else macosRelease;
archs = filterAttrs (n: _: elem n supportedSystems) {
x86_64-linux = linuxRelease.pkgsFor "x86_64-linux";
x86_64-darwin = macosRelease.pkgsFor "x86_64-darwin";
};
makeScripts = cluster: let
getScript = name: optionalAttrs linuxBuild {
x86_64-linux = archs.x86_64-linux.scripts.${cluster}.${name};
} // (optionalAttrs macosBuild {
x86_64-darwin = archs.x86_64-darwin.scripts.${cluster}.${name};
});
in {
node = getScript "node";
};
dockerImages = let
inherit (archs.${builtins.head supportedSystems}) dockerImage submitApiDockerImage;
in pkgs.runCommand "bcc-node-docker-images" {} ''
mkdir -pv $out/nix-support/
cat <<EOF > $out/nix-support/hydra-build-products
file binary-dist ${dockerImage}
file binary-dist ${submitApiDockerImage}
EOF
'';
mkPins = inputs: pkgs.runCommand "ifd-pins" {} ''
mkdir $out
cd $out
${concatMapStringsSep "\n" (input: "ln -sv ${input.value} ${input.key}") (attrValues (mapAttrs (key: value: { inherit key value; }) inputs))}
'';
makeRelease = cluster: {
name = cluster;
value = {
scripts = makeScripts cluster;
};
};
# Environments we want to build scripts for on hydra
environments = [ "mainnet" "testnet" "staging" "sophie_qa" "aurum-blue" "aurum-white" ];
extraBuilds = {
# Environments listed in Network Configuration page
bcc-deployment = pkgs.tbcoNix.bccLib.mkConfigHtml { inherit (pkgs.tbcoNix.bccLib.environments) mainnet testnet; };
} // (builtins.listToAttrs (map makeRelease environments));
# restrict supported systems to a subset where tests (if exist) are required to pass:
testsSupportedSystems = intersectLists supportedSystems [ "x86_64-linux" "x86_64-darwin" ];
# Recurse through an attrset, returning all derivations in a list matching test supported systems.
collectJobs' = ds: filter (d: elem d.system testsSupportedSystems) (collect isDerivation ds);
# Adds the package name to the derivations for windows-testing-bundle.nix
# (passthru.identifier.name does not survive mapTestOn)
collectJobs = ds: concatLists (
mapAttrsToList (packageName: package:
map (drv: drv // { inherit packageName; }) (collectJobs' package)
) ds);
nonDefaultBuildSystems = tail supportedSystems;
# Paths or prefixes of paths of derivations to build only on the default system (ie. linux on hydra):
onlyBuildOnDefaultSystem = [
["checks" "hlint"] ["dockerImage"] ["submitApiDockerImage"] ["clusterTests"] ["nixosTests"]
[ "haskellPackages" "bcc-node-chairman" "checks" ]
[ "haskellPackages" "bcc-node-chairman" "coverageReport" ]
[ "bcc-node-profiled" ] [ "bcc-node-eventlogged" ]
[ "checks" "tests" "bcc-node-chairman" ]
[ "workbench" ] [ "profiles" ]
[ "tx-generator" "components" "exes" ]
[ "tx-generator-profiled" ]
[ "locli-profiled" ]
];
# Paths or prefix of paths for which cross-builds (mingwW64, musl64) are disabled:
noCrossBuild = [
["shell"] ["devopsShell"] ["bcc-ping"] ["roots"]
[ "haskellPackages" "bcc-testnet" ]
[ "checks" "tests" "bcc-testnet" ]
[ "tests" "bcc-testnet" ]
] ++ onlyBuildOnDefaultSystem;
noMusl64Build = [ ["checks"] ["tests"] ["benchmarks"] ["haskellPackages"] ["plan-nix"]]
++ noCrossBuild;
# Remove build jobs for which cross compiling does not make sense.
filterProject = noBuildList: project: mapAttrsRecursiveCond (a: !(isDerivation a)) (path: value:
if (isDerivation value && (any (p: take (length p) path == p) noBuildList)) then null
else value
) project;
inherit (systems.examples) mingwW64 musl64;
inherit (pkgs.commonLib) sources nixpkgs;
jobs = {
inherit dockerImages;
ifd-pins = mkPins {
inherit (sources) tbco-nix "haskell.nix";
inherit nixpkgs;
inherit (pkgs.haskell-nix) hackageSrc stackageSrc;
};
} // (optionalAttrs linuxBuild (with linuxRelease; {
linux =
let filteredBuilds = mapAttrsRecursiveCond (a: !(isList a)) (path: value:
if (any (p: take (length p) path == p) onlyBuildOnDefaultSystem) then filter (s: !(elem s nonDefaultBuildSystems)) value else value)
(packagePlatforms project);
in {
native = mapTestOn (__trace (__toJSON filteredBuilds) filteredBuilds);
# linux static builds:
musl64 = mapTestOnCross musl64 (packagePlatformsCross (filterProject noMusl64Build project));
};
bcc-node-linux = import ./nix/binary-release.nix {
inherit (linuxRelease) pkgs project;
platform = "linux";
exes = collectJobs jobs.linux.musl64.exes;
};
})) // (optionalAttrs macosBuild (with macosRelease; {
macos =
let filteredBuilds = mapAttrsRecursiveCond (a: !(isList a)) (path: value:
if (any (p: take (length p) path == p) onlyBuildOnDefaultSystem) then filter (s: !(elem s nonDefaultBuildSystems)) value else value)
(packagePlatforms project);
in (mapTestOn (__trace (__toJSON filteredBuilds) filteredBuilds));
bcc-node-macos = import ./nix/binary-release.nix {
inherit pkgs project;
platform = "macos";
exes = collectJobs jobs.macos.exes;
};
})) // (optionalAttrs windowsBuild (with windowsRelease; {
windows = mapTestOnCross mingwW64 (packagePlatformsCross (filterProject noCrossBuild project));
bcc-node-win64 = import ./nix/binary-release.nix {
inherit pkgs project;
platform = "win64";
exes = collectJobs jobs.windows.exes;
};
})) // extraBuilds // (linuxRelease.mkRequiredJob (concatLists [
# Linux builds:
(optionals linuxBuild (concatLists [
(collectJobs jobs.linux.native.checks)
(collectJobs jobs.linux.native.nixosTests)
(collectJobs jobs.linux.native.benchmarks)
(collectJobs jobs.linux.native.exes)
(collectJobs jobs.linux.native.shell)
(collectJobs jobs.linux.native.devopsShell)
[ jobs.bcc-node-linux ]
]))
# macOS builds:
(optionals macosBuild (concatLists [
(collectJobs jobs.macos.checks)
(collectJobs jobs.macos.nixosTests)
(collectJobs jobs.macos.benchmarks)
(collectJobs jobs.macos.exes)
[ jobs.bcc-node-macos ]
]))
# Windows builds:
(optional windowsBuild jobs.bcc-node-win64)
(optionals windowsBuild (collectJobs jobs.windows.checks))
# Default system builds (linux on hydra):
(map (cluster: collectJobs jobs.${cluster}.scripts.node.${head supportedSystems}) environments)
[ jobs.dockerImages ]
]));
in jobs