-
Notifications
You must be signed in to change notification settings - Fork 1
/
rust.nix
60 lines (53 loc) · 1.49 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
{inputs}:
with inputs; let
buildRustEnv = {
pkgs,
src,
symlinks ? [],
}: let
craneLib = (crane.mkLib pkgs).overrideToolchain (fenix.packages.${pkgs.system}.latest.withComponents [
"cargo"
"clippy"
"rust-src"
"rustc"
"rustfmt"
]);
buildRustPackage = pname: features: let
features_cmd = builtins.concatStringsSep " " features;
commonArgs = {
inherit pname;
src = craneLib.cleanCargoSource (craneLib.path src);
version = "0.1";
strictDeps = true;
CARGO_BUILD_JOBS = -1;
nativeBuildInputs = with pkgs; [
pkg-config
];
preConfigurePhases = [
"link_local_deps"
];
link_local_deps = builtins.concatStringsSep "; " (builtins.map (path: "ln -s " + (craneLib.cleanCargoSource (craneLib.path path)) + " ./" + builtins.baseNameOf path) symlinks);
buildInputs = with pkgs;
[
openssl
]
++ lib.optionals stdenv.isDarwin [
# Additional darwin specific inputs can be set here
libiconv
darwin.apple_sdk.frameworks.SystemConfiguration
];
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
in
craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
cargoExtraArgs = "--bin ${pname} --features '${features_cmd}'";
}
);
in {
inherit buildRustPackage craneLib;
};
in
buildRustEnv