-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
155 lines (143 loc) · 5.86 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
{
# Note: same flake.nix as espresso-sequencer but with go and postgres for zkevm-node,
# commented out pre-commit hooks (for now).
description = "zkevm-node, with go and rust development environment";
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";
inputs.rust-overlay.url = "github:oxalica/rust-overlay";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.flake-compat.url = "github:edolstra/flake-compat";
inputs.flake-compat.flake = false;
# inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
outputs = { self, nixpkgs, rust-overlay, flake-utils, flake-compat, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
info = builtins.split "\([a-zA-Z0-9_]+\)" system;
arch = (builtins.elemAt (builtins.elemAt info 1) 0);
os = (builtins.elemAt (builtins.elemAt info 3) 0);
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
in
with pkgs;
{
# checks = {
# pre-commit-check = pre-commit-hooks.lib.${system}.run {
# src = ./.;
# hooks = {
# cargo-fmt = {
# enable = true;
# description = "Enforce rustfmt";
# entry = "cargo fmt --all";
# pass_filenames = false;
# };
# cargo-sort = {
# enable = true;
# description = "Ensure Cargo.toml are sorted";
# entry = "cargo sort -g -w";
# pass_filenames = false;
# };
# cargo-clippy = {
# enable = true;
# description = "Run clippy";
# entry = "cargo clippy --workspace --examples --bins --tests -- -D warnings";
# pass_filenames = false;
# };
# };
# };
# };
devShells.default =
let
stableToolchain = pkgs.rust-bin.stable.latest.minimal.override {
extensions = [ "rustfmt" "clippy" "llvm-tools-preview" "rust-src" ];
};
# 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
mkShell
{
buildInputs = [
# Rust dependencies
pkgconfig
openssl
curl
protobuf # to compile libp2p-autonat
stableToolchain
# Rust tools
cargo-edit
cargo-watch
cargo-sort
# Tools
nixWithFlakes
entr
# Figures
graphviz
plantuml
coreutils
# zkevm-node
go
docker-compose
postgresql_15
] ++ lib.optionals stdenv.isDarwin[darwin.apple_sdk.frameworks.SystemConfiguration];
shellHook = ''
# Prevent cargo aliases from using programs in `~/.cargo` to avoid conflicts
# with rustup installations.
export CARGO_HOME=$HOME/.cargo-nix
''
# + self.checks.${system}.pre-commit-check.shellHook
;
RUST_SRC_PATH = "${stableToolchain}/lib/rustlib/src/rust/library";
RUST_BACKTRACE = 1;
RUST_LOG = "info,libp2p=off";
};
devShells.staticShell =
let
muslPkgs = import nixpkgs {
localSystem = system;
crossSystem = { config = "${arch}-unknown-${os}-musl"; };
};
stableMuslRustToolchain =
pkgs.rust-bin.stable.latest.minimal.override {
extensions = [ "rustfmt" "clippy" "llvm-tools-preview" "rust-src" ];
targets = [ "${arch}-unknown-${os}-musl" ];
};
opensslMusl = muslPkgs.openssl.override { static = true; };
curlMusl = (muslPkgs.pkgsStatic.curl.override {
http2Support = false;
libssh2 = muslPkgs.pkgsStatic.libssh2.dev;
zstdSupport = false;
idnSupport = false;
}).overrideAttrs (oldAttrs:
let confFlags = oldAttrs.configureFlags;
in {
configureFlags = (muslPkgs.lib.take 13 confFlags)
++ (muslPkgs.lib.drop 14 confFlags)
++ [ (muslPkgs.lib.withFeature true "libssh2") ];
});
in
mkShell {
DEP_CURL_STATIC = "y";
"CARGO_TARGET_${pkgs.lib.toUpper arch}_UNKNOWN_${pkgs.lib.toUpper os}_MUSL_LINKER" =
"${pkgs.llvmPackages_latest.lld}/bin/lld";
RUSTFLAGS =
"-C target-feature=+crt-static -L${opensslMusl.out}/lib/ -L${curlMusl.out}/lib -L${muslPkgs.pkgsStatic.zstd.out}/lib -L${muslPkgs.pkgsStatic.libssh2}/lib -L${muslPkgs.pkgsStatic.openssl}/lib -lssh2";
OPENSSL_STATIC = "true";
OPENSSL_DIR = "-L${muslPkgs.pkgsStatic.openssl}";
OPENSSL_INCLUDE_DIR = "${opensslMusl.dev}/include/";
OPENSSL_LIB_DIR = "${opensslMusl.dev}/lib/";
CARGO_BUILD_TARGET = "${arch}-unknown-${os}-musl";
buildInputs = with pkgs;
[ protobuf stableMuslRustToolchain fd cmake ];
meta.broken = if "${os}" == "darwin" then true else false;
RUST_LOG = "info,libp2p=off";
};
}
);
}