generated from foundry-rs/foundry-rust-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
111 lines (103 loc) · 3.75 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
{
inputs = {
devenv.url = "github:cachix/devenv";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
flake-utils.url = "github:numtide/flake-utils";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
foundry = {
url = "github:shazow/foundry.nix/monthly";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, fenix, foundry, devenv }@inputs:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
foundry-pkg = foundry.defaultPackage.${system};
forge = "${foundry-pkg}/bin/forge";
channel = inputs.fenix.packages.${pkgs.system}.latest;
in {
devShell = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [{
packages = with pkgs;
[ solc gcc foundry-pkg go-ethereum cargo-watch ]
++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk; [
libiconv
frameworks.Security
frameworks.CoreFoundation
frameworks.SystemConfiguration
]);
dotenv.enable = true;
difftastic.enable = true;
# https://devenv.sh/languages/
languages.nix.enable = true;
languages.rust = {
enable = true;
toolchain = channel.toolchain;
};
scripts.bind-attack.exec = ''
${forge} install
${forge} fmt
${forge} bind -b ./attack/src/abi --module --force --overwrite
pre-commit run rustfmt -a > /dev/null || true
'';
scripts.bind-ctf.exec = ''
${forge} install --root ctf
${forge} fmt --root ctf
${forge} bind --root ctf -b ./ctf/src/abi --module --skip-cargo-toml --force --overwrite
pre-commit run rustfmt -a > /dev/null || true
'';
scripts.deploy-levels.exec = ''
if [ -f state.json ]; then
rm -v state.json
fi
cargo run --bin deploy_levels
'';
# https://devenv.sh/pre-commit-hooks/
pre-commit.hooks = {
nixfmt = {
enable = true;
fail_fast = true;
package = pkgs.nixfmt-classic;
};
rustfmt = {
enable = true;
packageOverrides = { inherit (channel) cargo rustfmt; };
};
# bind-attack-contracts = {
# enable = true;
# name = "Bind attack contracts";
# description =
# "Build attack/contracts/ contracts and generate Rust ABI bindings";
# files = "attack/contracts/.*.sol$";
# entry = ".devenv/profile/bin/bind-attack";
# pass_filenames = false;
# verbose = true;
# };
# bind-ctf-contracts = {
# enable = true;
# name = "Bind CTF contracts";
# description =
# "Compile CTF smart contracts and generate Rust ABI bindings";
# files = "ctf/contracts/.*.sol$";
# entry = ".devenv/profile/bin/bind-ctfs";
# pass_filenames = false;
# verbose = true;
# };
# deploy-levels = {
# enable = true;
# name = "Deploy levels";
# files = "ctf/src/.*.rs";
# entry = ".devenv/profile/bin/deploy-levels";
# pass_filenames = false;
# verbose = true;
# };
};
}];
};
});
}