forked from ipetkov/crane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvendorCargoDeps.nix
43 lines (37 loc) · 1.44 KB
/
vendorCargoDeps.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
{ findCargoFiles
, lib
, vendorMultipleCargoDeps
}:
args:
let
inherit (builtins)
pathExists
readFile;
inherit (lib.attrsets) optionalAttrs;
cargoConfigs = if args ? src then (findCargoFiles args.src).cargoConfigs else [ ];
src = args.src or (throw ''
unable to find `src` attribute. consider one of the following:
- set `cargoVendorDir = vendorCargoDeps { cargoLock = ./some/path/to/Cargo.lock; }`
- set `cargoVendorDir = vendorCargoDeps { src = ./src/containing/cargo/lock/file; }`
- set `cargoVendorDir = null` to skip vendoring altogether
'');
cargoLock = args.cargoLock or (src + "/Cargo.lock");
cargoLockContents = args.cargoLockContents or (
if pathExists cargoLock
then readFile cargoLock
else
throw ''
unable to find Cargo.lock at ${src}. please ensure one of the following:
- a Cargo.lock exists at the root of the source directory of the derivation
- set `cargoVendorDir = vendorCargoDeps { cargoLock = ./some/path/to/Cargo.lock; }`
- set `cargoVendorDir = vendorCargoDeps { src = ./src/containing/cargo/lock/file; }`
- set `cargoVendorDir = null` to skip vendoring altogether
''
);
lock = args.cargoLockParsed or (builtins.fromTOML cargoLockContents);
in
vendorMultipleCargoDeps ({
inherit cargoConfigs;
cargoLockParsedList = [ lock ];
outputHashes = args.outputHashes or { };
} // optionalAttrs (args ? registries) { inherit (args) registries; })