forked from MinaProtocol/mina
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
402 lines (364 loc) · 15.9 KB
/
flake.nix
File metadata and controls
402 lines (364 loc) · 15.9 KB
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
{
description =
"Mina, a cryptocurrency with a lightweight, constant-size blockchain";
nixConfig = {
allow-import-from-derivation = "true";
extra-substituters = [ "https://storage.googleapis.com/mina-nix-cache" ];
extra-trusted-public-keys = [
"nix-cache.minaprotocol.org:fdcuDzmnM0Kbf7yU4yywBuUEJWClySc1WIF6t6Mm8h4="
"nix-cache.minaprotocol.org:D3B1W+V7ND1Fmfii8EhbAbF1JXoe2Ct4N34OKChwk2c="
];
};
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";
inputs.nix-utils.url = "github:juliosueiras-nix/nix-utils";
outputs = inputs@{ self, nixpkgs, utils, mix-to-nix, nix-npm-buildPackage
, opam-nix, opam-repository, nixpkgs-mozilla, flake-buildkite-pipeline
, nix-utils, ... }:
{
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 {
derivationCache = "https://storage.googleapis.com/mina-nix-cache";
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; });
rpmDebUtils = final.callPackage "${nix-utils}/utils/rpm-deb" { };
})
] ++ 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 {
nodejs = pkgs.nodejs-16_x;
};
submodules = map builtins.head (builtins.filter lib.isList
(map (builtins.match " path = (.*)")
(lib.splitString "\n" (builtins.readFile ./.gitmodules))));
requireSubmodules = lib.warnIf (!builtins.all builtins.pathExists
(map (x: ./. + "/${x}") submodules)) ''
Some submodules are missing, you may get errors. Consider one of the following:
- run nix/pin.sh and use "mina" flake ref;
- use "git+file://$PWD?submodules=1";
- use "git+https://github.com/minaprotocol/mina?submodules=1";
- use non-flake commands like nix-build and nix-shell.
'';
checks = import ./nix/checks.nix inputs pkgs;
ocamlPackages = pkgs.ocamlPackages_mina;
debianPackages = pkgs.callPackage ./nix/debian.nix { };
# Packages for the development environment that are not needed to build mina-dev.
# For instance dependencies for tests.
devShellPackages = [ pkgs.rosetta-cli ];
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 ./node_modules/gentype/vendor-linux/gentype.exe
'';
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
'';
};
# snarkyjs
packages.snarky_js = nix-npm-buildPackage.buildNpmPackage {
src = ./src/lib/snarky_js_bindings/snarkyjs;
preBuild = ''
BINDINGS_PATH=./src/node_bindings
mkdir -p "$BINDINGS_PATH"
cp ${pkgs.plonk_wasm}/nodejs/plonk_wasm* "$BINDINGS_PATH"
cp ${ocamlPackages.mina_client_sdk}/share/snarkyjs_bindings/snarky_js_node*.js "$BINDINGS_PATH"
chmod -R 777 "$BINDINGS_PATH"
# TODO: deduplicate from ./scripts/build-snarkyjs-node.sh
# better error messages
# TODO: find a less hacky way to make adjustments to jsoo compiler output
# `s` is the jsoo representation of the error message string, and `s.c` is the actual JS string
sed -i 's/function failwith(s){throw \[0,Failure,s\]/function failwith(s){throw joo_global_object.Error(s.c)/' "$BINDINGS_PATH"/snarky_js_node.bc.js
sed -i 's/function invalid_arg(s){throw \[0,Invalid_argument,s\]/function invalid_arg(s){throw joo_global_object.Error(s.c)/' "$BINDINGS_PATH"/snarky_js_node.bc.js
sed -i 's/return \[0,Exn,t\]/return joo_global_object.Error(t.c)/' "$BINDINGS_PATH"/snarky_js_node.bc.js
'';
npmBuild = "npm run build";
# TODO: add snarky-run
# TODO
# checkPhase = "node ${./src/lib/snarky_js_bindings/tests/run-tests.mjs}"
};
packages.mina-signer = nix-npm-buildPackage.buildNpmPackage {
src = ./frontend/mina-signer;
preBuild = ''
cp ${ocamlPackages.mina_client_sdk}/share/client_sdk/client_sdk.bc.js src
chmod 0666 src/client_sdk.bc.js
cp ${pkgs.plonk_wasm}/nodejs/plonk_wasm{.js,_bg.wasm} src
chmod 0666 src/plonk_wasm{.js,_bg.wasm}
'';
npmBuild = "npm run build";
doCheck = true;
checkPhase = "npm test";
};
inherit ocamlPackages;
packages = {
inherit (ocamlPackages)
mina mina_tests mina-ocaml-format mina_client_sdk test_executive;
inherit (pkgs) libp2p_helper kimchi_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;
packages.mina-deb = debianPackages.mina;
devShell = ocamlPackages.mina-dev.overrideAttrs (oa: {
buildInputs = oa.buildInputs ++ devShellPackages;
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";
buildInputs = oa.buildInputs ++ devShellPackages;
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;
# A shell from which it's possible to build Mina with Rust bits being built incrementally using cargo.
# This is "impure" from the nix' perspective since running `cargo build` requires networking in general.
# However, this is a useful balance between purity and convenience for Rust development.
devShells.rust-impure = ocamlPackages.mina-dev.overrideAttrs (oa: {
name = "mina-rust-shell";
buildInputs = oa.buildInputs ++ devShellPackages;
nativeBuildInputs = oa.nativeBuildInputs ++ [
pkgs.rustup
pkgs.libiconv # needed on macOS for one of the rust dep
];
MARLIN_PLONK_STUBS = "n";
PLONK_WASM_WEB = "n";
PLONK_WASM_NODEJS = "n";
});
inherit checks;
});
}