-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
157 lines (139 loc) · 5.07 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
{
description = "A devShell example";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.flake-compat.url = "github:edolstra/flake-compat";
inputs.flake-compat.flake = false;
inputs.rust-overlay.url = "github:oxalica/rust-overlay";
inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
# See https://github.com/cachix/pre-commit-hooks.nix/pull/122
inputs.pre-commit-hooks.inputs.flake-utils.follows = "flake-utils";
inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
outputs =
{ self
, nixpkgs
, flake-utils
, flake-compat
, rust-overlay
, pre-commit-hooks
, ...
}:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
in
{
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
lint-solidity = {
enable = true;
files = "^contracts/contracts/";
entry = "lint-solidity";
types = [ "solidity" ];
};
check-format = {
enable = true;
entry = "treefmt --fail-on-change";
};
# The hook "clippy" that ships with nix-precommit-hooks is outdated.
cargo-clippy = {
enable = true;
description = "Lint Rust code.";
entry = "cargo-clippy --workspace -- -D warnings";
files = "\\.rs$";
pass_filenames = false;
};
};
};
};
devShell =
let
mySolc = pkgs.callPackage ./nix/solc-bin { version = "0.8.10"; };
pythonEnv = pkgs.poetry2nix.mkPoetryEnv {
projectDir = ./.;
overrides = pkgs.poetry2nix.overrides.withDefaults
(import ./nix/poetryOverrides.nix { inherit pkgs; });
};
myPython = with pkgs; [
poetry
pythonEnv
];
stableToolchain = pkgs.rust-bin.stable."1.58.0".minimal.override {
extensions = [ "rustfmt" "clippy" "llvm-tools-preview" "rust-src" ];
};
rustDeps = with pkgs; [
pkgconfig
openssl
curl
plantuml
stableToolchain
cargo-edit
] ++ lib.optionals stdenv.isDarwin [
# required to compile ethers-rs
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.CoreFoundation
# https://github.com/NixOS/nixpkgs/issues/126182
libiconv
] ++ lib.optionals (stdenv.system != "aarch64-darwin") [
cargo-watch # broken: https://github.com/NixOS/nixpkgs/issues/146349
];
# 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" "$@"
'';
in
pkgs.mkShell
{
buildInputs = with pkgs; [
nixWithFlakes
go-ethereum
nodePackages.pnpm
mySolc
hivemind # process runner
nodejs-16_x # nodejs
jq
entr # watch files for changes, for example: ls contracts/*.sol | entr -c hardhat compile
treefmt # multi language formatter
nixpkgs-fmt
git # required for pre-commit hook installation
netcat-gnu # only used to check for open ports
cacert
mdbook # make-doc, documentation generation
moreutils # includes `ts`, used to add timestamps on CI
]
++ myPython
++ rustDeps;
RUST_SRC_PATH = "${stableToolchain}/lib/rustlib/src/rust/library";
RUST_BACKTRACE = 1;
RUST_LOG = "info";
SOLCX_BINARY_PATH = "${mySolc}/bin";
SOLC_VERSION = mySolc.version;
SOLC_PATH = "${mySolc}/bin/solc";
SOLC_OPTIMIZER_RUNS = "1000000";
shellHook = ''
echo "Ensuring node dependencies are installed"
pnpm --recursive install
if [ ! -f .env ]; then
echo "Copying .env.sample to .env"
cp .env.sample .env
fi
echo "Exporting all vars in .env file"
set -a; source .env; set +a;
export CONTRACTS_DIR=$(pwd)/contracts
export HARDHAT_CONFIG=$CONTRACTS_DIR/hardhat.config.ts
export PATH=$(pwd)/node_modules/.bin:$PATH
export PATH=$CONTRACTS_DIR/node_modules/.bin:$PATH
export PATH=$(pwd)/bin:$PATH
git config --local blame.ignoreRevsFile .git-blame-ignore-revs
''
# install pre-commit hooks
+ self.checks.${system}.pre-commit-check.shellHook;
};
}
);
}