2022-02-07 04:16:49 +03:00
|
|
|
{ findCargoFiles
|
2022-01-31 01:30:15 +03:00
|
|
|
, lib
|
|
|
|
, runCommandLocal
|
2022-02-07 04:16:49 +03:00
|
|
|
, vendorCargoRegistries
|
2022-02-08 07:03:12 +03:00
|
|
|
, vendorGitDeps
|
2021-12-27 01:05:23 +03:00
|
|
|
}:
|
|
|
|
|
2022-01-09 04:52:10 +03:00
|
|
|
args:
|
2021-12-27 01:05:23 +03:00
|
|
|
let
|
2022-01-31 01:30:15 +03:00
|
|
|
inherit (builtins)
|
|
|
|
attrNames
|
|
|
|
pathExists
|
2022-02-07 04:16:49 +03:00
|
|
|
readFile;
|
2022-01-31 01:30:15 +03:00
|
|
|
|
|
|
|
inherit (lib)
|
|
|
|
concatMapStrings
|
2022-02-07 04:16:49 +03:00
|
|
|
escapeShellArg;
|
2022-01-31 01:30:15 +03:00
|
|
|
|
2022-01-09 04:52:10 +03:00
|
|
|
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
|
|
|
|
'');
|
|
|
|
|
2022-05-09 16:38:16 +03:00
|
|
|
cargoLock = args.cargoLock or (src + "/Cargo.lock");
|
2022-01-09 04:52:10 +03:00
|
|
|
cargoLockContents = args.cargoLockContents or (
|
2022-01-31 01:30:15 +03:00
|
|
|
if pathExists cargoLock
|
|
|
|
then readFile cargoLock
|
2022-01-09 04:52:10 +03:00
|
|
|
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
|
|
|
|
''
|
|
|
|
);
|
|
|
|
|
2022-02-08 07:03:12 +03:00
|
|
|
linkSources = sources: concatMapStrings
|
|
|
|
(name: ''
|
|
|
|
ln -s ${escapeShellArg sources.${name}} $out/${escapeShellArg name}
|
|
|
|
'')
|
|
|
|
(attrNames sources);
|
|
|
|
|
2023-03-20 03:33:17 +03:00
|
|
|
lock = args.cargoLockParsed or (builtins.fromTOML cargoLockContents);
|
2022-02-08 07:03:12 +03:00
|
|
|
lockPackages = lock.package or (throw "Cargo.lock missing [[package]] definitions");
|
|
|
|
|
2022-02-07 04:16:49 +03:00
|
|
|
vendoredRegistries = vendorCargoRegistries {
|
2022-02-08 07:03:12 +03:00
|
|
|
inherit lockPackages;
|
2022-02-07 04:16:49 +03:00
|
|
|
cargoConfigs = (findCargoFiles src).cargoConfigs;
|
|
|
|
};
|
2022-02-08 07:03:12 +03:00
|
|
|
vendoredGit = vendorGitDeps {
|
|
|
|
inherit lockPackages;
|
|
|
|
};
|
2021-12-27 01:05:23 +03:00
|
|
|
in
|
2022-02-07 04:16:49 +03:00
|
|
|
runCommandLocal "vendor-cargo-deps" { } ''
|
|
|
|
mkdir -p $out
|
|
|
|
cat >>$out/config.toml <<EOF
|
|
|
|
${vendoredRegistries.config}
|
2022-02-08 07:03:12 +03:00
|
|
|
${vendoredGit.config}
|
2022-02-07 04:16:49 +03:00
|
|
|
EOF
|
|
|
|
|
2022-02-08 07:03:12 +03:00
|
|
|
${linkSources vendoredRegistries.sources}
|
|
|
|
${linkSources vendoredGit.sources}
|
2022-02-07 04:16:49 +03:00
|
|
|
''
|