-
Notifications
You must be signed in to change notification settings - Fork 0
/
rust.nix
80 lines (80 loc) · 2.76 KB
/
rust.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
{ lib, pkgs, workspace-binaries, extra-overrides }:
let
rustPkgs = pkgs.rustBuilder.makePackageSet {
rustVersion = "latest";
packageFun = import ./Cargo.nix;
packageOverrides = p:
let
mkNativeDep = cratename: extra-deps:
p.rustBuilder.rustLib.makeOverride {
name = cratename;
overrideAttrs = drv: {
propagatedBuildInputs = (drv.propagatedBuildInputs or [ ])
++ extra-deps;
};
};
mkRpath = cratename: libs:
p.rustBuilder.rustLib.makeOverride {
name = cratename;
overrideAttrs = drv: {
preFixup = let libPath = lib.makeLibraryPath libs;
in ''
patchelf --set-rpath "${libPath}" $out/bin/${cratename}
'';
};
};
mkLdLibraryPath = cratename: libs:
mkNativeDep cratename [
(p.rustBuilder.overrides.patches.propagateEnv cratename [{
name = "LD_LIBRARY_PATH";
value = lib.makeLibraryPath libs;
}])
];
in [
(p.rustBuilder.rustLib.makeOverride {
overrideArgs = old: {
rustcLinkFlags = old.rustcLinkFlags or [ ] ++ [
"-C"
"linker=${pkgs.clang}/bin/clang"
"-C"
"link-arg=-fuse-ld=${pkgs.mold}/bin/mold"
];
};
})
(p.rustBuilder.rustLib.makeOverride {
registry = "registry+https://github.com/rust-lang/crates.io-index";
overrideArgs = old: {
rustcLinkFlags = old.rustcLinkFlags or [ ]
++ [ "--cap-lints" "warn" ];
};
})
] ++ (extra-overrides { inherit mkNativeDep p; }) ++ (builtins.concatLists
(builtins.attrValues (builtins.mapAttrs (cratename:
{ rpath, run_time_ld_library_path }: [
(p.rustBuilder.rustLib.makeOverride {
name = cratename;
overrideAttrs = drv: {
preFixup = let libPath = lib.makeLibraryPath (rpath p);
in ''
patchelf --set-rpath "${libPath}" $out/bin/${cratename}
'';
};
})
(mkLdLibraryPath cratename (run_time_ld_library_path p))
]) workspace-binaries)));
};
wrapIfHasLdLibraryPath = cratename:
{ rpath, run_time_ld_library_path }:
let
crate = rustPkgs.workspace.${cratename} { };
libPath = lib.makeLibraryPath (run_time_ld_library_path pkgs);
in (if libPath == "" then
crate
else
pkgs.writeShellScriptBin cratename ''
LD_LIBRARY_PATH="${libPath}" ${crate}/bin/${cratename}
'');
in {
inherit rustPkgs;
packages = builtins.mapAttrs wrapIfHasLdLibraryPath workspace-binaries;
}