forked from cargo2nix/cargo2nix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverrides.nix
293 lines (266 loc) · 8.56 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
{ rustLib, lib, pkgs, buildPackages }:
let
inherit (rustLib) makeOverride nullOverride;
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; };
};
propagateEnv = name: envs: buildPackages.stdenv.mkDerivation {
name = "${name}-propagate-env";
setupHook = buildPackages.writeText "exports.sh" ''
${name}-setup-env() {
${lib.concatMapStringsSep
"\n"
({ name, value }: "export ${name}=${lib.escapeShellArg value}")
envs}
}
addEnvHooks "$hostOffset" ${name}-setup-env
'';
phases = "installPhase fixupPhase";
installPhase = "mkdir -p $out";
preferLocalBuild = true;
allowSubstitutes = false;
};
in rec {
patches = { inherit patchOpenssl patchCurl patchPostgresql joinOpenssl propagateEnv; };
# 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
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" ]; };
};
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: {
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [
pkgs.dbus
];
};
};
libudev-sys = pkgs.rustBuilder.rustLib.makeOverride {
name = "libudev-sys";
overrideAttrs = drv: {
propagatedBuildInputs = drv.propagatedBuildInputs 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
pkgs.libgit2
];
preferLocalBuild = true;
allowSubstitutes = false;
};
}
else nullOverride;
libssh2-sys = makeOverride {
name = "libssh2-sys";
overrideAttrs = drv: {
propagatedNativeBuildInputs = drv.propagatedNativeBuildInputs or [ ] ++ [ pkgs.openssl.dev pkgs.zlib.dev ];
};
};
libsqlite3-sys = pkgs.rustBuilder.rustLib.makeOverride {
name = "libsqlite3-sys";
overrideAttrs = drv: {
propagatedNativeBuildInputs = drv.propagatedNativeBuildInputs or [ ] ++ [ pkgs.sqlite ];
};
};
openssl-sys = makeOverride {
name = "openssl-sys";
overrideAttrs = drv: {
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [
(propagateEnv "openssl-sys" [
{ name = "RUSTFLAGS"; value = "--cfg ossl111 --cfg ossl110 --cfg ossl101";}
{ name = "${envize (pkgs.rustBuilder.rustLib.rustTriple pkgs.stdenv.buildPlatform)}_OPENSSL_DIR"; value = joinOpenssl (patchOpenssl pkgs.buildPackages); }
{ name = "${envize (pkgs.rustBuilder.rustLib.rustTriple pkgs.stdenv.hostPlatform)}_OPENSSL_DIR"; value = joinOpenssl (patchOpenssl pkgs); }
{ name = "OPENSSL_NO_VENDOR"; value = "1";} # fixed 0.9.60
])
];
};
};
pkg-config = makeOverride {
name = "pkg-config";
overrideAttrs = drv: {
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [
pkgs.pkg-config
(propagateEnv "pkg-config" [
{ name = "PKG_CONFIG_ALLOW_CROSS"; value = "1"; }
])
];
};
};
pq-sys =
let
binEcho = s: "${pkgs.buildPackages.writeShellScriptBin "bin-echo" "echo ${s}"}/bin/bin-echo";
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.
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [
(propagateEnv "pq-sys" [
{ name = "PG_CONFIG_${envize pkgs.stdenv.buildPlatform.config}"; value = binEcho "${(patchPostgresql pkgs.buildPackages).lib}/lib"; }
{ name = "PG_CONFIG_${envize pkgs.stdenv.hostPlatform.config}"; value = binEcho "${(patchPostgresql pkgs).lib}/lib"; }
])
];
};
};
prost-build = makeOverride {
name = "prost-build";
overrideAttrs = drv: {
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [
(propagateEnv "prost-build" [
{ name = "PROTOC"; value = "${pkgs.buildPackages.buildPackages.protobuf}/bin/protoc"; }
])
];
};
};
protoc = makeOverride {
name = "protoc";
overrideAttrs = drv: {
propagatedBuildInputs = drv.propagatedBuildInputs 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;
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: {
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [ pkgs.zeromq ];
};
};
}