forked from cargo2nix/cargo2nix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverrides.nix
329 lines (296 loc) · 10.5 KB
/
overrides.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
{ rustLib, lib, pkgs, buildPackages }:
let
inherit (rustLib) makeOverride nullOverride;
# The bindings in this let expression are used below in the recursive set to
# create overrides. They are not themselves overrides. See the list of `all`
# overrides and their definitions below.
# For example, openssl builds to separate directories in nixpkgs while the
# Rust crate expects all of the output to be in one directory. We use a
# symlink join to create an output of the sum of two of openssl's normal
# outputs. This is one example of a nixpkg requiring some slight finesse to
# be used as a buildInput for a Rust crate derivation.
envize = s: builtins.replaceStrings ["-"] ["_"] (lib.toUpper s);
patchOpenssl = pkgs:
if pkgs.stdenv.hostPlatform.libc == "musl"
then pkgs.openssl.override {
static = true;
}
else if pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform
then pkgs.openssl
else (pkgs.openssl.override {
# We only need `perl` at build time. It's also used as the interpreter for one
# of the produced binaries (`c_rehash`), but they'll be removed later.
perl = pkgs.buildPackages.buildPackages.perl;
}).overrideAttrs (drv: {
installTargets = "install_sw";
outputs = [ "dev" "out" "bin" ];
# Remove binaries, we need only libraries.
postFixup = ''
${drv.postFixup}
rm -rf $bin/*
'';
});
joinOpenssl = openssl: buildPackages.symlinkJoin {
name = "openssl"; paths = with openssl; [ out dev ];
};
patchPostgresql = pkgs: pkgs.postgresql.override {
openssl = patchOpenssl pkgs;
# Remove `systemd` input as it breaks cross compilation.
enableSystemd = false;
};
patchCurl = pkgs:
let
openssl = patchOpenssl pkgs;
in pkgs.curl.override {
inherit openssl;
nghttp2 = pkgs.nghttp2.override { inherit openssl; };
libssh2 = pkgs.libssh2.override { inherit openssl; };
libkrb5 = pkgs.libkrb5.override { inherit openssl; };
};
in rec {
patches = { inherit patchOpenssl patchCurl patchPostgresql joinOpenssl;};
# Don't forget to add new overrides here.
all = [
capLints
cc
curl-sys
fsevent-sys
libgit2-sys
libdbus-sys
libssh2-sys
libudev-sys
openssl-sys
pkg-config
pq-sys
prost-build
protoc
rand
rand_os
rdkafka-sys
sqlx-macros
reqwest
ring
zmq-sys
];
capLints = makeOverride {
registry = "registry+https://github.com/rust-lang/crates.io-index";
overrideArgs = old: { rustcLinkFlags = old.rustcLinkFlags or [ ] ++ [ "--cap-lints" "warn" ]; };
};
# Every crate that depends on the cc crate (usually build scripts) will have the xcbuild
cc = if pkgs.stdenv.hostPlatform.isDarwin
then makeOverride {
name = "cc";
overrideAttrs = drv: {
propagatedNativeBuildInputs = drv.propagatedNativeBuildInputs or [ ] ++ [
pkgs.xcbuild
];
};
}
else nullOverride;
curl-sys = makeOverride {
name = "curl-sys";
overrideAttrs = drv: {
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [
(patchCurl pkgs)
];
};
};
fsevent-sys = if pkgs.stdenv.hostPlatform.isDarwin
then makeOverride {
name = "fsevent-sys";
overrideAttrs = drv: {
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [
pkgs.darwin.apple_sdk.frameworks.CoreServices
];
};
}
else nullOverride;
reqwest = if pkgs.stdenv.hostPlatform.isDarwin
then makeOverride {
name = "reqwest";
overrideAttrs = drv: {
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [
pkgs.darwin.apple_sdk.frameworks.Security
];
};
}
else nullOverride;
libdbus-sys = pkgs.rustBuilder.rustLib.makeOverride {
name = "libdbus-sys";
overrideAttrs = drv: {
buildInputs = drv.buildInputs or [ ] ++ [
pkgs.dbus
];
};
};
libudev-sys = pkgs.rustBuilder.rustLib.makeOverride {
name = "libudev-sys";
overrideAttrs = drv: {
buildInputs = drv.buildInputs or [ ] ++ [
pkgs.udev
];
buildPhase = ''
runHook overrideCargoManifest
runHook setBuildEnv
export PATH=$PATH:$(dirname $RUSTC)
runHook runCargo
'';
};
};
libgit2-sys = if pkgs.stdenv.hostPlatform.isDarwin
then makeOverride {
name = "libgit2-sys";
overrideAttrs = drv: {
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.darwin.apple_sdk.frameworks.CoreFoundation
];
buildInputs = drv.buildInputs or [ ] ++ [
pkgs.libgit2
];
preferLocalBuild = true;
allowSubstitutes = false;
};
}
else nullOverride;
libssh2-sys = makeOverride {
name = "libssh2-sys";
overrideAttrs = drv: {
buildInputs = drv.buildInputs or [ ] ++ [ pkgs.openssl.dev pkgs.zlib.dev ];
};
};
libsqlite3-sys = pkgs.rustBuilder.rustLib.makeOverride {
name = "libsqlite3-sys";
overrideAttrs = drv: {
buildInputs = drv.buildInputs or [ ] ++ [ pkgs.sqlite ];
};
};
openssl-sys = makeOverride {
name = "openssl-sys";
overrideAttrs = drv: {
# The setup hook will set the variables both for building openssl-sys and
# in dependent derivations. This mechanism will also set the variable
# inside our development shell. Because the setupHook does not add the
# joinOpenssl derivation as a dependnecy, we have to include it in
# nativeBuildInputs as well or the variable will point to a path not
# visible to the derivation at build time.
buildInputs = drv.buildInputs or [ ] ++ [(joinOpenssl (patchOpenssl pkgs.buildPackages))];
shellHook = drv.shellHook or "" + ''
export ${envize (pkgs.rustBuilder.rustLib.rustTriple pkgs.stdenv.buildPlatform)}_OPENSSL_DIR=${lib.escapeShellArg (joinOpenssl (patchOpenssl pkgs.buildPackages))}
export ${envize (pkgs.rustBuilder.rustLib.rustTriple pkgs.stdenv.hostPlatform)}_OPENSSL_DIR=${lib.escapeShellArg (joinOpenssl (patchOpenssl pkgs))}
export OPENSSL_NO_VENDOR=1 # fixed 0.9.60
export RUSTFLAGS="''${RUSTFLAGS:-} --cfg ossl111 --cfg ossl110 --cfg ossl101"
'';
# setupHook is also a means of injecting the build environment for a dependency
# setupHook = buildPackages.writeText "openssl-sys-setup-env.sh" ''
# openssl-sys-setup-env() {
# export ${envize (pkgs.rustBuilder.rustLib.rustTriple pkgs.stdenv.buildPlatform)}_OPENSSL_DIR=${lib.escapeShellArg (joinOpenssl (patchOpenssl pkgs.buildPackages))}
# export ${envize (pkgs.rustBuilder.rustLib.rustTriple pkgs.stdenv.hostPlatform)}_OPENSSL_DIR=${lib.escapeShellArg (joinOpenssl (patchOpenssl pkgs))}
# export OPENSSL_NO_VENDOR=1 # fixed 0.9.60
# export RUSTFLAGS="''${RUSTFLAGS:-} --cfg ossl111 --cfg ossl110 --cfg ossl101"
# }
# addEnvHooks "$hostOffset" openssl-sys-setup-env
# '';
};
};
pkg-config = makeOverride {
name = "pkg-config";
overrideAttrs = drv: {
# Every crate that depends on the pkg-config crate also gets pkg-config and this environment
propagatedNativeBuildInputs = drv.propagatedNativeBuildInputs or [ ] ++ [
pkgs.pkg-config
];
shellHook = drv.shellHook or "" + ''
export PGK_CONFIG_ALLOW_CROSS=1
'';
};
};
pq-sys =
let
binEcho = s: "${pkgs.buildPackages.writeShellScriptBin "bin-echo" "echo ${s}"}/bin/bin-echo";
fake_pg_config = binEcho "${(patchPostgresql pkgs.buildPackages).lib}/lib";
in
makeOverride {
name = "pq-sys";
overrideAttrs = drv: {
# We can't use the host `pg_config` here, as it might not run on build platform. `pq-sys` only needs
# to know the `lib` directory for `libpq`, so just create a fake binary that gives it exactly that.
nativeBuildInputs = drv.nativeBuildInputs or [ ] ++ [
fake_pg_config
];
shellHook = drv.shellHook + ''
PG_CONFIG_${envize pkgs.stdenv.buildPlatform.config}="${fake_pg_config}"
'';
};
};
# Note that protobuff is from buildPackages and runs at the crate's
# build-time, so it's a nativeBuildInput. Every crate that depends on
# prost-build might need protoc at runtime, so it's propagated.
prost-build = makeOverride {
name = "prost-build";
overrideAttrs = drv: {
setupHook = buildPackages.writeText "prost-build-setup-env.sh" ''
prost-build-setup-env () {
PROTOC="${pkgs.buildPackages.buildPackages.protobuf}/bin/protoc"
}
addEnvHooks "$hostOffset" prost-build-setup-env
'';
propagatedNativeBuildInputs = drv.propagatedNativeBuildInputs or [ ] ++ [
pkgs.buildPackages.buildPackages.protobuf
];
};
};
protoc = makeOverride {
name = "protoc";
overrideAttrs = drv: {
propagatedNativeBuildInputs = drv.propagatedNativeBuildInputs or [ ] ++ [ pkgs.buildPackages.buildPackages.protobuf ];
};
};
rand = if pkgs.stdenv.hostPlatform.isDarwin
then makeOverride {
name = "rand";
overrideAttrs = drv: {
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [ pkgs.darwin.apple_sdk.frameworks.Security ];
};
}
else nullOverride;
rand_os = if pkgs.stdenv.hostPlatform.isDarwin
then makeOverride {
name = "rand_os";
overrideAttrs = drv: {
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [ pkgs.darwin.apple_sdk.frameworks.Security ];
};
}
else nullOverride;
sqlx-macros = if pkgs.stdenv.hostPlatform.isDarwin
then makeOverride {
name = "sqlx-macros";
overrideAttrs = drv: {
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [ pkgs.darwin.apple_sdk.frameworks.SystemConfiguration ];
};
}
else nullOverride;
rdkafka-sys = makeOverride {
name = "rdkafka-sys";
overrideAttrs = drv: {
postConfigure = ''
${drv.postConfigure or ""}
patchShebangs --build librdkafka/configure
'';
};
};
ring = if pkgs.stdenv.hostPlatform.isDarwin
then makeOverride {
name = "ring";
overrideAttrs = drv: {
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [ pkgs.darwin.apple_sdk.frameworks.Security ];
};
}
else nullOverride;
zmq-sys = makeOverride {
name = "zmq-sys";
overrideAttrs = drv: {
buildInputs = drv.buildInputs or [ ] ++ [ pkgs.zeromq ];
};
};
}