forked from cargo2nix/cargo2nix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser-facing.nix
118 lines (112 loc) · 4.4 KB
/
user-facing.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
{
pkgs,
buildPackages,
stdenv,
rustBuilder,
}:
args@{
# required arg
packageFun,
# optional args
rustChannel ? null,
rustVersion ? null,
rustToolchain ? null,
rustProfile ? "minimal",
extraRustComponents ? [],
packageOverrides ? pkgs: pkgs.rustBuilder.overrides.all,
target ? null,
workspaceSrc ? null,
ignoreLockHash ? false,
...
}:
let
# These are used in this function, and we clean them out for downstream
extraArgs = builtins.removeAttrs args [ "rustChannel"
"rustVersion"
"rustProfile"
"rustToolchain"
"extraRustComponents"
"packageFun"
"nixifiedLockHash"
"packageOverrides"
"target" ];
# Rust targets don't always map perfectly to Nix targets, so they are allowed
# to be independent by specicying an explicit Rust target.
toolchainArgs = {
extensions = [ "rust-src" ] ++ extraRustComponents;
targets = [(rustBuilder.rustLib.rustTriple stdenv.buildPlatform)] ++
(if target != null
then [ target ]
else [ (rustBuilder.rustLib.rustTriple stdenv.hostPlatform) ]);
};
# Normalize the toolchain args and build a toolchain or used the provided
# toolchain. This logic is a bit complicated by legacy use of "rustChannel"
# wich could be a version string in previous eras. Can deprecate at some
# point after pointing everyone to correct usage. Note that rustToolchain
# comes from buildPackages.rust-bin. The overlay has been applied and
# returned via callPackage.
rustToolchain' =
if rustToolchain != null
then
rustToolchain
else
if rustChannel == "nightly"
then
if rustVersion == null || rustVersion == "latest"
then
# don't use explicit "latest" attribute! See oxalica README for more details.
buildPackages.rust-bin.selectLatestNightlyWith
(toolchain: toolchain.${rustProfile}.override toolchainArgs)
else
buildPackages.rust-bin.nightly
.${args.rustVersion}
.${rustProfile}.override toolchainArgs
else
if ((rustChannel != null &&
(builtins.match "[0-9]\.[0-9]{1,2}\.[0-9]{1,2}" rustChannel) != null))
then
if rustVersion != null
then
builtins.throw "You gave rustChannel a version but also specified rustVersion (╯=▃= )╯︵┻━┻"
else
# rustChannel is actually a rustVersion. Treat argument as legacy.
buildPackages.rust-bin.stable
.${args.rustChannel}
.${rustProfile}.override toolchainArgs
else
let
rustChannel' = if rustChannel != null then rustChannel else "stable";
in
buildPackages.rust-bin
.${rustChannel'}
.${args.rustVersion}
.${rustProfile}.override toolchainArgs;
# Cargo2nix requires a rustc in order to run. This runtime dependency is
# grafted on here to avoid noise in the flake and because we know what Rust
# toolchain is in use at this point of expression.
packageOverrides' = pkgs: packageOverrides (pkgs) ++ [(pkgs.rustBuilder.rustLib.makeOverride {
name = "cargo2nix";
overrideAttrs = drv: {
nativeBuildInputs = drv.nativeBuildInputs or [] ++ [ pkgs.makeWrapper ];
postFixup = ''
if [[ -x $bin/bin/cargo2nix ]]; then
wrapProgram $bin/bin/cargo2nix --prefix PATH : ${pkgs.lib.makeBinPath [ rustToolchain' ]};
fi
'';
};
})];
# This expression finally evaluates the result of makePackageSet.
# makePackageSetInternal is where overrides are applied and the splice is
# performed. Note that buildRustPackages is just buildPackages with a null
# target.
in rustBuilder.makePackageSetInternal (extraArgs // {
inherit packageFun ignoreLockHash workspaceSrc target;
rustToolchain = rustToolchain';
packageOverrides = packageOverrides' pkgs;
buildRustPackages = buildPackages.rustBuilder.makePackageSetInternal (extraArgs // {
inherit packageFun ignoreLockHash workspaceSrc;
rustToolchain = rustToolchain';
target = null;
packageOverrides = packageOverrides' buildPackages;
});
})