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
160 lines (136 loc) · 4.33 KB
/
Copy pathflake.nix
File metadata and controls
160 lines (136 loc) · 4.33 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
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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/25.11";
nixpkgs-llvm22.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
nixpkgs-llvm22,
utils,
crane,
fenix,
...
}:
utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
llvm22Pkgs = import nixpkgs-llvm22 { 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;
llvm22 = llvm22Pkgs.llvmPackages_22;
nativeBuildInputs = [
pkgs.pkg-config
pkgs.libgit2
pkgs.m4
pkgs.perl
];
buildInputs = [
pkgs.libffi
pkgs.libxml2
pkgs.ncurses
pkgs.zlib
];
withClang = prev: {
buildInputs = prev.buildInputs or [] ++ [
pkgs.clang
];
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
};
withLlvm22 = prev: {
nativeBuildInputs = prev.nativeBuildInputs or [] ++ [
llvm22.llvm.dev
];
buildInputs = prev.buildInputs or [] ++ [
llvm22.llvm.lib
];
LLVM_SYS_221_PREFIX = "${llvm22.llvm.dev}";
};
withLlvm22DevShell = prev: (withLlvm22 prev) // {
packages = prev.packages or [] ++ [
llvm22.llvm.dev
llvm22.llvm.lib
];
};
withMaxPerf = prev: {
cargoBuildCommand = "cargo build --profile=maxperf";
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"
];
};
withVergenBypass = prev: {
preBuild = ''
export VERGEN_GIT_SHA=${self.rev or self.dirtyRev}
export VERGEN_GIT_DIRTY=${if self ? rev then "false" else "true"}
export VERGEN_GIT_DESCRIBE=${self.shortRev or self.dirtyRev}
'';
};
mkReth = overrides: craneLib.buildPackage (composeAttrOverrides {
pname = "reth";
version = packageVersion;
src = ./.;
inherit nativeBuildInputs buildInputs;
doCheck = false;
} overrides);
in
{
packages = rec {
reth = mkReth ([
withClang
withLlvm22
withMaxPerf
withVergenBypass
] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
withMold
]);
default = reth;
};
devShell = let
overrides = [
withClang
withLlvm22DevShell
] ++ 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);
}
);
}