-
Notifications
You must be signed in to change notification settings - Fork 271
Expand file tree
/
Copy pathflake.nix
More file actions
133 lines (118 loc) · 3.81 KB
/
flake.nix
File metadata and controls
133 lines (118 loc) · 3.81 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/25.11";
utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
fenix.url = "github:nix-community/fenix";
};
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";
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"
];
};
mkTempo =
overrides:
craneLib.buildPackage (
composeAttrOverrides {
pname = "tempo";
version = packageVersion;
src = ./.;
inherit nativeBuildInputs;
doCheck = false;
} overrides
);
in
{
# TODO `nix build` is broken due to a Nix bug: builtins.fetchGit with
# allRefs=true (used by crane for bare rev= git deps) fails when Nix's
# internal git cache has stale refs from deleted/force-pushed branches.
# The reth git deps in Cargo.toml use bare rev= without a branch/tag,
# which triggers this. Adding `branch = "main"` to the reth git deps in
# Cargo.toml would fix it by letting crane use allRefs=false.
#
# packages = rec {
# tempo = mkTempo (
# [
# withClang
# withMaxPerf
# ]
# ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
# withMold
# ]
# );
#
# default = tempo;
# };
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
);
}
);
}