forked from EspressoSystems/HotShot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
307 lines (267 loc) · 10.4 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
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
{
description = "HotShot consensus library";
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/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
crate2nix = {
url = "github:balsoft/crate2nix/balsoft/fix-broken-ifd";
flake = false;
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
cargo-careful = {
url = "github:RalfJung/cargo-careful";
flake = false;
};
};
outputs =
{ self, nixpkgs, flake-compat, utils, crate2nix, fenix, cargo-careful }:
utils.lib.eachDefaultSystem (system:
let
fenixNightly = fenix.packages.${system}.latest.withComponents [
"cargo"
"clippy"
"rust-src"
"rustc"
"rustfmt"
"llvm-tools-preview"
];
fenixStable = fenix.packages.${system}.combine [
(fenix.packages.${system}.latest.withComponents [
"rustfmt"
])
(fenix.packages.${system}.fromToolchainFile {
dir = ./.;
sha256 = "sha256-yMuSb5eQPO/bHv+Bcf/US8LVMbf/G/0MSfiPwBhiPpk=";
})
];
# needed for compiling static binary
fenixMusl = with fenix.packages.${system};
combine [
(stable.withComponents [ "cargo" "clippy" "rustc" "rustfmt" ])
targets.x86_64-unknown-linux-musl.stable.rust-std
];
CARGO_TARGET_DIR = "target_dirs/nix_rustc";
pkgs = import nixpkgs {
inherit system;
};
pkgsAllowUnfree = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
heapstack_pkgs = import nixpkgs { inherit system; };
tokio-console = pkgs.rustPlatform.buildRustPackage rec {
pname = "tokio-console";
version = "0.1.7";
src = pkgs.fetchFromGitHub {
owner = "tokio-rs";
repo = "console";
rev = "tokio-console-v${version}";
sha256 = "sha256-yTNLKpBkzzN0X73CjN/UXRGjAGOnCCgJa6A6loA6baM=";
};
cargoSha256 = "sha256-K/auhqlL/K6RYE0lHyvSUqK1cOwJBBZD3QTUevZzLXQ=";
nativeBuildInputs = [ pkgs.protobuf ];
meta = with pkgs.lib; {
description = "A debugger for asynchronous Rust code";
homepage = "https://github.com/tokio-rs/console";
license = with licenses; [ mit ];
maintainers = with maintainers; [ max-niederman ];
};
doCheck = false;
};
careful = pkgs.rustPlatform.buildRustPackage {
pname = "cargo-careful";
version = "master";
src = cargo-careful;
cargoSha256 = "sha256-5H6Dp3YANVGYxvphTdnd92+0h0ddFX7u5SWT24YxzV4=";
meta = {
description = "A cargo undefined behaviour checker";
homepage = "https://github.com/RalfJung/cargo-careful";
};
};
cargo-llvm-cov = pkgs.rustPlatform.buildRustPackage rec {
pname = "cargo-llvm-cov";
version = "0.3.0";
doCheck = false;
buildInputs = [ pkgs.libllvm ];
src = builtins.fetchTarball {
url =
"https://crates.io/api/v1/crates/${pname}/${version}/download";
sha256 =
"sha256:0iswa2cdaf2123vfc42yj9l8jx53k5jm2y51d4xqc1672hi4620l";
};
cargoSha256 = "sha256-RzIkW/eytU8ZdZ18x0sGriJ2xvjVW+8hB85In12dXMg=";
meta = {
description = "Cargo llvm cov generates code coverage via llvm.";
homepage = "https://github.com/taiki-e/cargo-llvm-cov";
};
};
# DON'T FORGET TO PUT YOUR PACKAGE NAME HERE, REMOVING `throw`
crateName = "hotshot";
inherit (import "${crate2nix}/tools.nix" { inherit pkgs; })
generatedCargoNix;
project = import (generatedCargoNix {
name = crateName;
src = ./.;
}) {
inherit pkgs;
rootFeatures = [ "docs" "blake3" ];
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
# Crate dependency overrides go here
# pass in protobuf
prost-build = attrs: {
buildInputs = [ pkgs.protobuf ];
PROTOC = "${pkgs.protobuf}/bin/protoc";
PROTOC_INCLUDE = "${pkgs.protobuf}/include";
};
libp2p-core = attrs: {
buildInputs = [ pkgs.protobuf ];
PROTOC = "${pkgs.protobuf}/bin/protoc";
PROTOC_INCLUDE = "${pkgs.protobuf}/include";
};
};
};
# TODO uncomment when fetching dependencies is unborked
# pkgsAndChecksList = pkgs.lib.mapAttrsToList (name: val: { packages.${name} = val.build; checks.${name} = val.build.override { runTests = true; }; }) project.workspaceMembers;
# # programmatically generate output packages based on what exists in the workspace
# pkgsAndChecksAttrSet = pkgs.lib.foldAttrs (n: a: pkgs.lib.recursiveUpdate n a) { } pkgsAndChecksList;
buildDepsSimple = with pkgs;
[
cargo-vet
curl.out
cargo-expand
cargo-workspaces
cargo-audit
nixpkgs-fmt
git-chglog
protobuf
python3
zlib.dev
zlib.out
just
pkg-config
openssl.dev
openssl.out
] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.CoreServices
pkgs.libiconv
darwin.apple_sdk.frameworks.SystemConfiguration
];
buildDeps = buildDepsSimple ++ [ fenix.packages.${system}.rust-analyzer ];
in {
devShell = pkgs.mkShell {
inherit CARGO_TARGET_DIR;
buildInputs = [ fenixStable ] ++ buildDeps;
};
devShells = {
# A simple shell without rust-analyzer
simpleShell = pkgs.mkShell {
inherit CARGO_TARGET_DIR;
buildInputs = [ fenixStable ] ++ buildDepsSimple;
};
# usage: check correctness
correctnessShell = pkgs.mkShell {
inherit CARGO_TARGET_DIR;
shellHook = ''
ulimit -n 1024
'';
RUST_SRC_PATH = "${fenixNightly}/lib/rustlib/src/rust/library";
RUST_LIB_SRC = "${fenixNightly}/lib/rustlib/src/rust/library";
buildInputs = [ careful pkgs.git fenixNightly pkgs.cargo-udeps ] ++ buildDeps;
};
semverShell = pkgs.mkShell {
inherit CARGO_TARGET_DIR;
buildInputs = [
(pkgs.cargo-semver-checks.overrideAttrs (final: prev: {doCheck = false;}))
fenixStable
] ++ buildDeps;
};
# usage: compile a statically linked musl binary
staticShell = pkgs.mkShell {
inherit CARGO_TARGET_DIR;
shellHook = ''
ulimit -n 1024
export RUSTFLAGS='-C target-feature=+crt-static'
export CARGO_BUILD_TARGET='x86_64-unknown-linux-musl'
'';
buildInputs = [ fenixMusl ] ++ buildDeps;
};
# usage: link with mold
moldShell = pkgs.mkShell {
inherit CARGO_TARGET_DIR;
LD_LIBRARY_PATH = "${pkgs.zlib.out}/lib";
buildInputs = with pkgs; [ zlib.out fd fenixStable ] ++ buildDeps;
shellHook = ''
export RUSTFLAGS='-Clinker=${pkgs.clang}/bin/clang -Clink-arg=-fuse-ld=${pkgs.mold}/bin/mold'
'';
};
# usage: setup for tokio with console
# with support for opentelemetry
consoleShell = pkgs.mkShell {
inherit CARGO_TARGET_DIR;
OTEL_BSP_MAX_EXPORT_BATCH_SIZE = 25;
OTEL_BSP_MAX_QUEUE_SIZE = 32768;
OTL_ENABLED = "true";
TOKIO_CONSOLE_ENABLED = "true";
RUSTFLAGS = "--cfg tokio_unstable";
RUST_LOG = "tokio=trace,runtime=trace";
LD_LIBRARY_PATH = "${pkgs.openssl.out}/lib/";
OPENSSL_INCLUDE_DIR = "${pkgs.openssl.dev}/include/";
OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib/";
buildInputs = with pkgs;
[ openssl.dev openssl.out tokio-console fenixStable ripgrep ]
++ buildDeps;
};
# usage: evaluate performance (llvm-cov + flamegraph)
perfShell = pkgs.mkShell {
inherit CARGO_TARGET_DIR;
buildInputs = with pkgs;
[ cargo-flamegraph fd cargo-llvm-cov fenixStable ripgrep ]
++ buildDeps ++ lib.optionals stdenv.isLinux [
heapstack_pkgs.heaptrack
pkgs.valgrind
];
};
# usage: brings in debugging tools including:
# - lldb: a debugger to be used with vscode
debugShell = pkgs.mkShell {
inherit CARGO_TARGET_DIR;
buildInputs = with pkgs; [ fenixStable lldb ] ++ buildDeps;
};
# run with `nix develop .#cudaShell`
cudaShell =
let cudatoolkit = pkgsAllowUnfree.cudaPackages_12_3.cudatoolkit;
in pkgs.mkShell {
inherit CARGO_TARGET_DIR;
buildInputs = with pkgs; [ cmake cudatoolkit util-linux gcc11 fenixStable ] ++ buildDeps;
shellHook = ''
export PATH="${pkgs.gcc11}/bin:${cudatoolkit}/bin:${cudatoolkit}/nvvm/bin:$PATH"
export LD_LIBRARY_PATH=${cudatoolkit}/lib
export CUDA_PATH=${cudatoolkit}
export CPATH="${cudatoolkit}/include"
export LIBRARY_PATH="$LIBRARY_PATH:/lib"
export CMAKE_CUDA_COMPILER=$CUDA_PATH/bin/nvcc
export LIBCLANG_PATH=${pkgs.llvmPackages_15.libclang.lib}/lib
export CFLAGS=""
'';
};
};
# TODO uncomment when fetching dependencies is unborked
# packages = pkgsAndChecksAttrSet.packages;
# checks = pkgsAndChecksAttrSet.checks;
# defaultPackage = project.workspaceMembers.hotshot.build;
});
}