-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathflake.nix
More file actions
384 lines (353 loc) · 12.4 KB
/
Copy pathflake.nix
File metadata and controls
384 lines (353 loc) · 12.4 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
{
description = "Espresso Decentralized Sequencer";
nixConfig = {
extra-substituters = [
"https://espresso-systems-private.cachix.org"
"https://nixpkgs-cross-overlay.cachix.org"
];
extra-trusted-public-keys = [
"espresso-systems-private.cachix.org-1:LHYk03zKQCeZ4dvg3NctyCq88e44oBZVug5LpYKjPRI="
"nixpkgs-cross-overlay.cachix.org-1:TjKExGN4ys960TlsGqNOI/NBdoz2Jdr2ow1VybWV5JM="
];
};
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.rust-overlay.url = "github:oxalica/rust-overlay";
inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
inputs.nixpkgs-cross-overlay.url = "github:alekseysidorov/nixpkgs-cross-overlay";
inputs.nixpkgs-cross-overlay.inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.solc-bin.url = "github:EspressoSystems/nix-solc-bin";
inputs.solc-bin.inputs.nixpkgs.follows = "nixpkgs";
inputs.dregs.url = "github:EspressoSystems/dregs";
inputs.flake-compat.url = "github:edolstra/flake-compat";
inputs.flake-compat.flake = false;
inputs.git-hooks.url = "github:cachix/git-hooks.nix";
inputs.git-hooks.inputs.nixpkgs.follows = "nixpkgs";
# Pinned echidna version - current nixpkgs version fails to build
# See https://hydra.nixos.org/job/nixos/trunk-combined/nixpkgs.echidna.x86_64-linux for build status
inputs.echidna-nixpkgs.url = "github:NixOS/nixpkgs/08dacfca559e1d7da38f3cf05f1f45ee9bfd213c";
outputs =
{ self
, nixpkgs
, rust-overlay
, nixpkgs-cross-overlay
, flake-utils
, git-hooks
, solc-bin
, echidna-nixpkgs
, dregs
, ...
}:
flake-utils.lib.eachDefaultSystem (system:
let
# node=error: disable noisy anvil output
RUST_LOG = "info,libp2p=off,isahc=error,surf=error,node=error";
RUST_BACKTRACE = 1;
rustEnvVars = { inherit RUST_LOG RUST_BACKTRACE; };
rustShellHook = ''
# on mac os `bin/pwd -P` returns the canonical path on case insensitive file-systems
my_pwd=$(/bin/pwd -P 2> /dev/null || pwd)
# Use a distinct target dir for builds from within nix shells.
export CARGO_TARGET_DIR="$my_pwd/target/nix"
# Add rust binaries to PATH
export PATH="$CARGO_TARGET_DIR/debug:$PATH"
'';
overlays = [
(import rust-overlay)
solc-bin.overlays.default
dregs.overlays.default
(final: prev: {
solhint = prev.callPackage ./nix/solhint { };
pup = prev.callPackage ./nix/pup { };
})
(final: prev: {
golangci-lint = prev.golangci-lint.overrideAttrs (old: rec {
version = "1.64.8";
src = prev.fetchFromGitHub {
owner = "golangci";
repo = "golangci-lint";
rev = "v${version}";
sha256 = "sha256-ODnNBwtfILD0Uy2AKDR/e76ZrdyaOGlCktVUcf9ujy8";
};
vendorHash = "sha256-/iq7Ju7c2gS7gZn3n+y0kLtPn2Nn8HY/YdqSDYjtEkI=";
});
})
(final: prev: {
prek-as-pre-commit = final.runCommand "prek-as-pre-commit" { } ''
mkdir -p $out/bin
ln -s ${final.prek}/bin/prek $out/bin/pre-commit
'';
})
];
pkgs = import nixpkgs { inherit system overlays; };
myShell = pkgs.mkShellNoCC.override (pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
# The mold linker is around 50% faster on Linux than the default linker.
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.clangStdenv;
});
crossShell = { config }:
let
localSystem = system;
crossSystem = {
inherit config;
useLLVM = true;
isStatic = true;
};
pkgs = import "${nixpkgs-cross-overlay}/utils/nixpkgs.nix" {
inherit overlays localSystem crossSystem;
};
in
import ./cross-shell.nix
{
inherit pkgs rustShellHook;
envVars = rustEnvVars;
};
in
with pkgs; {
checks = {
pre-commit-check = git-hooks.lib.${system}.run {
src = ./.;
# Use the rust pre-commit implementation `prek`
imports = [
({ lib, ... }: {
config.package = lib.mkForce prek;
})
];
hooks = {
doc = {
enable = true;
description = "Generate figures";
entry = "make doc";
types_or = [ "plantuml" ];
pass_filenames = false;
};
rustfmt = {
enable = true;
description = "Run rustfmt on changed files";
# cargo-fmt is slower, does not format all files, and doesn't allow passing file arguments
entry = "rustfmt";
types_or = [ "rust" ];
pass_filenames = true;
};
cargo-sort = {
enable = true;
description = "Ensure Cargo.toml are sorted";
entry = "cargo sort -g -w";
types_or = [ "toml" ];
pass_filenames = false;
};
cargo-lock = {
enable = true;
description = "Ensure Cargo.lock is compatible with Cargo.toml";
entry = "cargo update --workspace --verbose";
types_or = [ "toml" ];
pass_filenames = false;
};
forge-fmt = {
enable = true;
description = "Enforce forge fmt";
entry = "forge fmt";
types_or = [ "solidity" ];
pass_filenames = false;
};
solhint = {
enable = true;
description = "Solidity linter";
entry = "solhint 'contracts/{script,src,test}/**/*.sol'";
types_or = [ "solidity" ];
pass_filenames = true;
};
contract-bindings = {
enable = true;
description = "Generate contract bindings";
entry = "just gen-bindings";
types_or = [ "solidity" ];
pass_filenames = false;
};
prettier-fmt = {
enable = true;
description = "Enforce markdown formatting";
entry = "prettier -w";
types_or = [ "markdown" ];
pass_filenames = true;
};
spell-checking = {
enable = true;
description = "Spell checking";
# --force-exclude to exclude excluded files if they are passed as arguments
entry = "typos --force-exclude";
pass_filenames = true;
# Add excludes to the .typos.toml file instead
};
nixpkgs-fmt.enable = true;
};
};
};
devShells.default =
let
stableToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
nightlyToolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal.override {
extensions = [ "rust-analyzer" "rustfmt" ];
});
solc = pkgs.solc-bin."0.8.35";
pre-commit = self.checks.${system}.pre-commit-check;
in
myShell (rustEnvVars // {
packages = [
# Rust dependencies
pkg-config
openssl
curl
protobuf # to compile libp2p-autonat
stableToolchain
jq
# Rust tools
cargo-audit
cargo-edit
cargo-hack
cargo-nextest
cargo-sort
typos
just
nightlyToolchain.passthru.availableComponents.rust-analyzer
nightlyToolchain.passthru.availableComponents.rustfmt
# Tools
nixpkgs-fmt
prek
prek-as-pre-commit # compat to allow running pre-commit
entr
pup
process-compose
lazydocker # a docker compose TUI
# `postgresql` defaults to an older version (15), so we select the latest version (16)
# explicitly.
postgresql_16
# Figures
graphviz
plantuml
coreutils
# Ethereum contracts, solidity, ...
foundry
solc
dregs-unwrapped
prettier
solhint
libusb1
mdbook
# scripts
bc
python3
uv
ruff
ty
uv
go
golangci-lint
# provides abigen
go-ethereum
] ++ lib.optionals stdenv.isDarwin [ darwin.libresolv ]
++ lib.optionals (!stdenv.isDarwin) [ cargo-watch ] # broken on OSX
++ pre-commit.enabledPackages;
shellHook = ''
${rustShellHook}
# Add the local scripts to the PATH
export PATH="$my_pwd/scripts:$PATH"
# Prevent cargo aliases from using programs in `~/.cargo` to avoid conflicts
# with rustup installations.
export CARGO_HOME=$HOME/.cargo-nix
# Let uv-installed binary wheels (matplotlib/numpy/...) find libstdc++ on NixOS.
export LD_LIBRARY_PATH="${lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib pkgs.zlib ]}''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
${pre-commit.shellHook}
'';
RUST_SRC_PATH = "${stableToolchain}/lib/rustlib/src/rust/library";
FOUNDRY_SOLC = "${solc}/bin/solc";
});
devShells.dockerShell = pkgs.mkShell {
inputsFrom = [ self.devShells.${system}.default ];
packages = [ pkgs.docker ];
shellHook = lib.concatStringsSep "\n" [
self.devShells.${system}.default
''
# Required for demo-native to run with docker-rootless
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock
''
];
};
devShells.crossShell =
crossShell { config = "x86_64-unknown-linux-musl"; };
devShells.armCrossShell =
crossShell { config = "aarch64-unknown-linux-musl"; };
devShells.nightly =
let
toolchain = pkgs.rust-bin.nightly.latest.minimal.override {
extensions = [ "rustfmt" "clippy" "llvm-tools-preview" "rust-src" ];
};
in
myShell (rustEnvVars // {
packages = [
# Rust dependencies
pkg-config
openssl
curl
protobuf # to compile libp2p-autonat
toolchain
];
shellHook = rustShellHook;
});
devShells.coverage =
let
toolchain = pkgs.rust-bin.nightly.latest.minimal;
in
myShell (rustEnvVars // {
packages = [
# Rust dependencies
pkg-config
openssl
curl
protobuf # to compile libp2p-autonat
toolchain
grcov
];
CARGO_INCREMENTAL = "0";
shellHook = ''
${rustShellHook}
RUSTFLAGS="$RUSTFLAGS -Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests -Cdebuginfo=2"
'';
RUSTDOCFLAGS = "-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests";
});
devShells.rustShell =
let
stableToolchain = pkgs.rust-bin.stable.latest.minimal.override {
extensions = [ "rustfmt" "clippy" "llvm-tools-preview" "rust-src" ];
};
in
myShell (rustEnvVars // {
packages = [
# Rust dependencies
pkg-config
openssl
curl
protobuf # to compile libp2p-autonat
stableToolchain
];
shellHook = rustShellHook;
});
# A separate dev-shell due to large size of dependencies (incl. ghc)
devShells.echidna =
let
solc = pkgs.solc-bin."0.8.28";
echidna-pkgs = import echidna-nixpkgs { inherit system; };
in
myShell {
packages = [
# Foundry tools
foundry
solc
# Security analysis tools
echidna-pkgs.slither-analyzer
echidna-pkgs.echidna
echidna-pkgs.python3.pkgs.crytic-compile
];
FOUNDRY_SOLC = "${solc}/bin/solc";
};
});
}