forked from MinaProtocol/mina
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
331 lines (302 loc) · 12.5 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
{
description =
"Mina, a cryptocurrency with a lightweight, constant-size blockchain";
nixConfig = {
# allow-import-from-derivation = "true";
};
inputs.utils.url = "github:gytis-ivaskevicius/flake-utils-plus";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable-small";
inputs.mix-to-nix.url = "github:serokell/mix-to-nix";
inputs.nix-npm-buildPackage.url = "github:serokell/nix-npm-buildpackage";
inputs.nix-npm-buildPackage.inputs.nixpkgs.follows = "nixpkgs";
inputs.opam-nix.url = "github:tweag/opam-nix";
inputs.opam-nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.opam-nix.inputs.opam-repository.follows = "opam-repository";
inputs.opam-repository.url = "github:ocaml/opam-repository";
inputs.opam-repository.flake = false;
inputs.nixpkgs-mozilla.url = "github:mozilla/nixpkgs-mozilla";
inputs.nixpkgs-mozilla.flake = false;
# For nix/compat.nix
inputs.flake-compat.url = "github:edolstra/flake-compat";
inputs.flake-compat.flake = false;
inputs.gitignore-nix.url = "github:hercules-ci/gitignore.nix";
inputs.gitignore-nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.nix-filter.url = "github:numtide/nix-filter";
inputs.flake-buildkite-pipeline.url = "github:tweag/flake-buildkite-pipeline";
outputs = inputs@{ self, nixpkgs, utils, mix-to-nix, nix-npm-buildPackage
, opam-nix, opam-repository, nixpkgs-mozilla, flake-buildkite-pipeline, ...
}:
{
overlays = {
misc = import ./nix/misc.nix;
rust = import ./nix/rust.nix;
go = import ./nix/go.nix;
};
nixosModules.mina = import ./nix/modules/mina.nix inputs;
nixosConfigurations.container = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = let
PK = "B62qiZfzW27eavtPrnF6DeDSAKEjXuGFdkouC3T5STRa6rrYLiDUP2p";
wallet = {
box_primitive = "xsalsa20poly1305";
ciphertext =
"Dmq1Qd8uNbZRT1NT7zVbn3eubpn9Myx9Je9ZQGTKDxUv4BoPNmZAGox18qVfbbEUSuhT4ZGDt";
nonce = "6pcvpWSLkMi393dT5VSLR6ft56AWKkCYRqJoYia";
pw_primitive = "argon2i";
pwdiff = [ 134217728 6 ];
pwsalt = "ASoBkV3NsY7ZRuxztyPJdmJCiz3R";
};
wallet-file = builtins.toFile "mina-wallet" (builtins.toJSON wallet);
wallet-file-pub = builtins.toFile "mina-wallet-pub" PK;
in [
self.nixosModules.mina
{
boot.isContainer = true;
networking.useDHCP = false;
networking.firewall.enable = false;
services.mina = {
enable = true;
config = {
"ledger" = {
"name" = "mina-demo";
"accounts" = [{
"pk" = PK;
"balance" = "66000";
"sk" = null;
"delegate" = null;
}];
};
};
waitForRpc = false;
external-ip = "0.0.0.0";
generate-genesis-proof = true;
seed = true;
block-producer-key = "/var/lib/mina/wallets/store/${PK}";
extraArgs = [
"--demo-mode"
"--proof-level"
"none"
"--run-snark-worker"
"B62qjnkjj3zDxhEfxbn1qZhUawVeLsUr2GCzEz8m1MDztiBouNsiMUL"
"-insecure-rest-server"
];
};
systemd.services.mina = {
preStart = ''
printf '{"genesis":{"genesis_state_timestamp":"%s"}}' "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" > /var/lib/mina/daemon.json
'';
environment = {
MINA_TIME_OFFSET = "0";
MINA_PRIVKEY_PASS = "";
};
};
systemd.tmpfiles.rules = [
"C /var/lib/mina/wallets/store/${PK}.pub 700 mina mina - ${wallet-file-pub}"
"C /var/lib/mina/wallets/store/${PK} 700 mina mina - ${wallet-file}"
];
}
];
};
pipeline = with flake-buildkite-pipeline.lib;
let
pushToRegistry = package: {
command = runInEnv self.devShells.x86_64-linux.operations ''
skopeo \
copy \
--insecure-policy \
--dest-registry-token $(gcloud auth application-default print-access-token) \
docker-archive:${self.packages.x86_64-linux.${package}} \
docker://us-west2-docker.pkg.dev/o1labs-192920/nix-containers/${package}:$BUILDKITE_BRANCH
'';
label = "Upload ${package} to Google Artifact Registry";
depends_on = [ "packages_x86_64-linux_${package}" ];
plugins = [{ "thedyrt/skip-checkout#v0.1.1" = null; }];
branches = [ "compatible" "develop" ];
};
publishDocs = {
command = runInEnv self.devShells.x86_64-linux.operations ''
gcloud auth activate-service-account --key-file "$GOOGLE_APPLICATION_CREDENTIALS"
gsutil -m rsync -rd ${self.defaultPackage.x86_64-linux}/share/doc/html gs://mina-docs
'';
label = "Publish documentation to Google Storage";
depends_on = [ "defaultPackage_x86_64-linux" ];
branches = [ "develop" ];
plugins = [{ "thedyrt/skip-checkout#v0.1.1" = null; }];
};
in {
steps = flakeSteps {
reproduceRepo = "mina";
commonExtraStepConfig = {
agents = [ "nix" ];
plugins = [{ "thedyrt/skip-checkout#v0.1.1" = null; }];
};
} self ++ [
(pushToRegistry "mina-docker")
(pushToRegistry "mina-daemon-docker")
publishDocs
];
};
} // utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system}.extend
(nixpkgs.lib.composeManyExtensions ([
(import nixpkgs-mozilla)
(final: prev: {
ocamlPackages_mina = requireSubmodules
(import ./nix/ocaml.nix { inherit inputs pkgs; });
})
] ++ builtins.attrValues self.overlays));
inherit (pkgs) lib;
mix-to-nix = pkgs.callPackage inputs.mix-to-nix { };
nix-npm-buildPackage = pkgs.callPackage inputs.nix-npm-buildPackage { };
submodules = map builtins.head (builtins.filter lib.isList
(map (builtins.match " path = (.*)")
(lib.splitString "\n" (builtins.readFile ./.gitmodules))));
requireSubmodules = let
ref = r: "[34;1m${r}[31;1m";
command = c: "[37;1m${c}[31;1m";
in lib.warnIf (!builtins.all (x: x)
(map (x: builtins.pathExists ./${x} && builtins.readDir ./${x} != { }) submodules)) ''
Some submodules are missing, you may get errors. Consider one of the following:
- run ${command "nix/pin.sh"} and use "${ref "mina"}" flake ref, e.g. ${command "nix develop mina"} or ${command "nix build mina"};
- use "${ref "git+file://$PWD?submodules=1"}";
- use "${ref "git+https://github.com/minaprotocol/mina?submodules=1"}";
- use non-flake commands like ${command "nix-build"} and ${command "nix-shell"}.
'';
checks = import ./nix/checks.nix inputs pkgs;
ocamlPackages = pkgs.ocamlPackages_mina;
in {
# Jobs/Lint/Rust.dhall
packages.trace-tool = pkgs.rustPlatform.buildRustPackage rec {
pname = "trace-tool";
version = "0.1.0";
src = ./src/app/trace-tool;
cargoLock.lockFile = ./src/app/trace-tool/Cargo.lock;
};
# Jobs/Lint/ValidationService
# Jobs/Test/ValidationService
packages.validation = ((mix-to-nix.override {
beamPackages = pkgs.beam.packagesWith pkgs.erlangR22; # todo: jose
}).mixToNix {
src = ./src/app/validation;
# todo: think about fixhexdep overlay
# todo: dialyze
overlay = (final: previous: {
goth = previous.goth.overrideAttrs
(o: { preConfigure = "sed -i '/warnings_as_errors/d' mix.exs"; });
});
}).overrideAttrs (o: {
# workaround for requiring --allow-import-from-derivation
# during 'nix flake show'
name = "coda_validation-0.1.0";
version = "0.1.0";
});
# Jobs/Release/LeaderboardArtifact
packages.leaderboard = nix-npm-buildPackage.buildYarnPackage {
src = ./frontend/leaderboard;
yarnBuildMore = "yarn build";
# fix reason
yarnPostLink = pkgs.writeScript "yarn-post-link" ''
#!${pkgs.stdenv.shell}
ls node_modules/bs-platform/lib/*.linux
patchelf \
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${pkgs.stdenv.cc.cc.lib}/lib" \
./node_modules/bs-platform/lib/*.linux ./node_modules/bs-platform/vendor/ninja/snapshot/*.linux
'';
# todo: external stdlib @rescript/std
preInstall = ''
shopt -s extglob
rm -rf node_modules/bs-platform/lib/!(js)
rm -rf node_modules/bs-platform/!(lib)
rm -rf yarn-cache
'';
};
# TODO: fix bs-platform build correctly
packages.client_sdk = nix-npm-buildPackage.buildYarnPackage {
name = "client_sdk";
src = ./frontend/client_sdk;
yarnPostLink = pkgs.writeScript "yarn-post-link" ''
#!${pkgs.stdenv.shell}
ls node_modules/bs-platform/lib/*.linux
patchelf \
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${pkgs.stdenv.cc.cc.lib}/lib" \
./node_modules/bs-platform/lib/*.linux ./node_modules/bs-platform/vendor/ninja/snapshot/*.linux
'';
yarnBuildMore = ''
cp ${ocamlPackages.mina_client_sdk}/share/client_sdk/client_sdk.bc.js src
yarn build
'';
installPhase = ''
mkdir -p $out/share/client_sdk
mv src/*.js $out/share/client_sdk
'';
};
inherit ocamlPackages;
packages = {
inherit (ocamlPackages)
mina devnet mainnet mina_tests mina-ocaml-format mina_client_sdk test_executive;
inherit (pkgs) libp2p_helper marlin_plonk_bindings_stubs;
};
packages.mina-docker = pkgs.dockerTools.buildImage {
name = "mina";
copyToRoot = pkgs.buildEnv {
name = "mina-image-root";
paths = [ ocamlPackages.mina.out ];
pathsToLink = [ "/bin" "/share" "/etc" ];
};
};
packages.mina-daemon-docker = pkgs.dockerTools.buildImage {
name = "mina-daemon";
copyToRoot = pkgs.buildEnv {
name = "mina-daemon-image-root";
paths = [
pkgs.dumb-init
pkgs.coreutils
pkgs.bashInteractive
pkgs.python3
pkgs.libp2p_helper
ocamlPackages.mina.out
ocamlPackages.mina.mainnet
ocamlPackages.mina.genesis
ocamlPackages.mina_build_config
ocamlPackages.mina_daemon_scripts
];
pathsToLink = [ "/bin" "/share" "/etc" ];
};
config = {
env = [ "MINA_TIME_OFFSET=0" ];
cmd = [ "/bin/dumb-init" "/entrypoint.sh" ];
};
};
legacyPackages.musl = pkgs.pkgsMusl;
legacyPackages.regular = pkgs;
defaultPackage = ocamlPackages.mina;
packages.default = ocamlPackages.mina;
devShell = ocamlPackages.mina-dev.overrideAttrs (oa: {
shellHook = ''
${oa.shellHook}
unset MINA_COMMIT_DATE MINA_COMMIT_SHA1 MINA_BRANCH
'';
});
devShells.default = self.devShell.${system};
devShells.with-lsp = ocamlPackages.mina-dev.overrideAttrs (oa: {
name = "mina-with-lsp";
nativeBuildInputs = oa.nativeBuildInputs
++ [ ocamlPackages.ocaml-lsp-server ];
shellHook = ''
${oa.shellHook}
unset MINA_COMMIT_DATE MINA_COMMIT_SHA1 MINA_BRANCH
# TODO: dead code doesn't allow us to have nice things
pushd src/app/cli
dune build @check
popd
'';
});
devShells.operations =
pkgs.mkShell { packages = with pkgs; [ skopeo google-cloud-sdk ]; };
devShells.impure = import ./nix/impure-shell.nix pkgs;
inherit checks;
});
}