-
-
Notifications
You must be signed in to change notification settings - Fork 127
/
default.nix
59 lines (52 loc) · 1.55 KB
/
default.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
{
lib,
pkgs,
externals,
...
}: {
subsystemAttrs,
defaultPackageName,
defaultPackageVersion,
getCyclicDependencies,
getDependencies,
getSource,
getSourceSpec,
packages,
produceDerivation,
...
} @ args: let
l = lib // builtins;
utils = import ../utils.nix args;
vendoring = import ../vendor.nix (args // {inherit lib pkgs utils;});
crane = externals.crane;
buildPackage = pname: version: let
src = utils.getRootSource pname version;
cargoVendorDir = vendoring.vendorDependencies pname version;
postUnpack = ''
export CARGO_HOME=$(pwd)/.cargo_home
'';
preConfigure = ''
${vendoring.writeGitVendorEntries "nix-sources"}
'';
# The deps-only derivation will use this as a prefix to the `pname`
depsNameSuffix = "-deps";
common = {inherit pname version src cargoVendorDir preConfigure postUnpack;};
depsArgs = common // {pnameSuffix = depsNameSuffix;};
deps = produceDerivation "${pname}${depsNameSuffix}" (crane.buildDepsOnly depsArgs);
buildArgs =
common
// {
cargoArtifacts = deps;
# Make sure cargo only builds & tests the package we want
cargoBuildCommand = "cargo build --release --package ${pname}";
cargoTestCommand = "cargo test --release --package ${pname}";
};
in
produceDerivation pname (crane.buildPackage buildArgs);
in rec {
packages =
l.mapAttrs
(name: version: {"${version}" = buildPackage name version;})
args.packages;
defaultPackage = packages."${defaultPackageName}"."${defaultPackageVersion}";
}