-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
140 lines (131 loc) · 4.15 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
{
description = "Dev env for zkRollup integration with Espresso";
nixConfig = {
extra-substituters = [ "https://espresso-systems-private.cachix.org" ];
extra-trusted-public-keys = [
"espresso-systems-private.cachix.org-1:LHYk03zKQCeZ4dvg3NctyCq88e44oBZVug5LpYKjPRI="
];
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-compat.follows = "flake-compat";
};
};
foundry.url =
"github:shazow/foundry.nix/monthly"; # Use monthly branch for permanent releases
solc-bin.url = "github:EspressoSystems/nix-solc-bin";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs =
{ self
, nixpkgs
, flake-utils
, flake-compat
, pre-commit-hooks
, foundry
, solc-bin
, rust-overlay
, ...
}:
flake-utils.lib.eachDefaultSystem (system:
let
overlays =
[ foundry.overlay solc-bin.overlays.default (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
nightlyRustToolchain = pkgs.rust-bin.nightly.latest.minimal.override {
extensions = [
"clippy"
"llvm-tools-preview"
"rustc-dev"
"rust-analyzer"
"rustfmt"
];
};
in
with pkgs; {
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
check-format = {
enable = true;
files = "\\.rs$";
entry = "cargo fmt -- --check";
};
cargo-clippy = {
enable = true;
description = "Lint Rust code.";
entry = "cargo-clippy --workspace -- -D warnings";
files = "\\.rs$";
pass_filenames = false;
};
cargo-sort = {
enable = true;
description = "Ensure Cargo.toml are sorted";
entry = "cargo sort sp1/program sp1/script";
pass_filenames = false;
};
forge-fmt = {
enable = true;
description = "Enforce forge fmt";
entry = "forge fmt";
types_or = [ "solidity" ];
pass_filenames = false;
};
spell-check = {
enable = true;
description = "Spell check";
entry = "typos";
pass_filenames = false;
};
nixpkgs-fmt.enable = true;
};
};
};
devShells.default =
let
# nixWithFlakes allows pre v2.4 nix installations to use
# flake commands (like `nix flake update`)
nixWithFlakes = pkgs.writeShellScriptBin "nix" ''
exec ${pkgs.nixFlakes}/bin/nix --experimental-features "nix-command flakes" "$@"
'';
solc = pkgs.solc-bin.latest;
in
mkShell {
buildInputs = [
git
nixWithFlakes
entr
typos
just
# Ethereum contracts, solidity, ...
foundry-bin
solc
# Rust
nightlyRustToolchain
cargo-sort
] ++ lib.optionals stdenv.isDarwin
[ darwin.apple_sdk.frameworks.SystemConfiguration ];
shellHook = ''
export RUST_BACKTRACE=full
export RUST_LOG=info
export PATH="$PATH:$(pwd)/target/debug:$(pwd)/target/release"
# Prevent cargo aliases from using programs in `~/.cargo` to avoid conflicts with local rustup installations.
export CARGO_HOME=$HOME/.cargo-nix
# Ensure `cargo fmt` uses `rustfmt` from nightly.
export RUSTFMT="${nightlyRustToolchain}/bin/rustfmt"
'' + self.checks.${system}.pre-commit-check.shellHook;
FOUNDRY_SOLC = "${solc}/bin/solc";
CARGO_TARGET_DIR = "target/nix_rustc";
};
});
}