forked from paradigmxyz/reth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
131 lines (110 loc) · 3.52 KB
/
flake.nix
File metadata and controls
131 lines (110 loc) · 3.52 KB
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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/24.11";
utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
nixpkgs,
utils,
crane,
fenix,
...
}:
utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
# A useful helper for folding a list of `prevSet -> newSet` functions
# into an attribute set.
composeAttrOverrides = defaultAttrs: overrides: builtins.foldl'
(acc: f: acc // (f acc)) defaultAttrs overrides;
cargoTarget = pkgs.stdenv.hostPlatform.rust.rustcTargetSpec;
cargoTargetEnvVar = builtins.replaceStrings ["-"] ["_"]
(pkgs.lib.toUpper cargoTarget);
cargoTOML = builtins.fromTOML (builtins.readFile ./Cargo.toml);
packageVersion = cargoTOML.workspace.package.version;
rustStable = fenix.packages.${system}.stable.withComponents [
"cargo" "rustc" "rust-src" "clippy"
];
rustNightly = fenix.packages.${system}.latest;
craneLib = (crane.mkLib pkgs).overrideToolchain rustStable;
nativeBuildInputs = [
pkgs.pkg-config
pkgs.libgit2
pkgs.perl
];
withClang = prev: {
buildInputs = prev.buildInputs or [] ++ [
pkgs.clang
];
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
};
withMaxPerf = prev: {
cargoBuildCommand = "cargo build --profile=maxperf";
cargoExtraArgs = prev.cargoExtraArgs or "" + " --features=jemalloc,asm-keccak";
RUSTFLAGS = prev.RUSTFLAGS or [] ++ [
"-Ctarget-cpu=native"
];
};
withMold = prev: {
buildInputs = prev.buildInputs or [] ++ [
pkgs.mold
];
"CARGO_TARGET_${cargoTargetEnvVar}_LINKER" = "${pkgs.llvmPackages.clangUseLLVM}/bin/clang";
RUSTFLAGS = prev.RUSTFLAGS or [] ++ [
"-Clink-arg=-fuse-ld=${pkgs.mold}/bin/mold"
];
};
withOp = prev: {
cargoExtraArgs = prev.cargoExtraArgs or "" + " -p op-reth --bin=op-reth";
};
mkReth = overrides: craneLib.buildPackage (composeAttrOverrides {
pname = "reth";
version = packageVersion;
src = ./.;
inherit nativeBuildInputs;
doCheck = false;
} overrides);
in
{
packages = rec {
reth = mkReth ([
withClang
withMaxPerf
] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
withMold
]);
op-reth = mkReth ([
withClang
withMaxPerf
withOp
] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
withMold
]);
default = reth;
};
devShell = let
overrides = [
withClang
] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
withMold
];
in craneLib.devShell (composeAttrOverrides {
packages = nativeBuildInputs ++ [
rustNightly.rust-analyzer
rustNightly.rustfmt
pkgs.cargo-nextest
];
# Remove the hardening added by nix to fix jmalloc compilation error.
# More info: https://github.com/tikv/jemallocator/issues/108
hardeningDisable = [ "fortify" ];
} overrides);
}
);
}