2023-04-02 20:57:17 +03:00
|
|
|
{ lib
|
2024-01-28 22:08:44 +03:00
|
|
|
, pkgsBuildBuild
|
2023-04-02 20:57:17 +03:00
|
|
|
, vendorCargoRegistries
|
|
|
|
, vendorGitDeps
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2024-01-28 22:08:44 +03:00
|
|
|
inherit (pkgsBuildBuild)
|
|
|
|
runCommandLocal;
|
|
|
|
|
2023-04-02 20:57:17 +03:00
|
|
|
inherit (builtins)
|
|
|
|
attrNames
|
|
|
|
attrValues
|
|
|
|
fromTOML
|
|
|
|
readFile;
|
|
|
|
|
|
|
|
inherit (lib)
|
|
|
|
concatMapStrings
|
2024-03-08 22:53:46 +03:00
|
|
|
escapeShellArg
|
|
|
|
groupBy;
|
2023-04-02 20:57:17 +03:00
|
|
|
|
|
|
|
inherit (lib.attrsets)
|
2023-04-03 02:46:24 +03:00
|
|
|
filterAttrs
|
2023-04-02 20:57:17 +03:00
|
|
|
optionalAttrs;
|
|
|
|
|
|
|
|
inherit (lib.lists)
|
|
|
|
flatten
|
|
|
|
unique;
|
2024-01-28 22:08:44 +03:00
|
|
|
in
|
|
|
|
{ cargoConfigs ? [ ]
|
|
|
|
, cargoLockContentsList ? [ ]
|
|
|
|
, cargoLockList ? [ ]
|
|
|
|
, cargoLockParsedList ? [ ]
|
|
|
|
, outputHashes ? { }
|
2024-03-05 06:53:19 +03:00
|
|
|
, registries ? null
|
|
|
|
}:
|
2024-01-28 22:08:44 +03:00
|
|
|
let
|
2023-04-02 20:57:17 +03:00
|
|
|
cargoLocksParsed = (map fromTOML ((map readFile cargoLockList) ++ cargoLockContentsList))
|
|
|
|
++ cargoLockParsedList;
|
2023-04-03 02:46:24 +03:00
|
|
|
|
|
|
|
# Extract all packages from all Cargo.locks and trim any unused attributes from the parsed
|
|
|
|
# data so we do not get any faux duplicates
|
|
|
|
allowedAttrs = {
|
|
|
|
name = true;
|
|
|
|
version = true;
|
|
|
|
source = true;
|
|
|
|
checksum = true;
|
|
|
|
};
|
|
|
|
allPackagesTrimmed = map
|
|
|
|
(l: map
|
|
|
|
(filterAttrs (k: _: allowedAttrs.${k} or false))
|
|
|
|
(l.package or [ ])
|
|
|
|
)
|
|
|
|
cargoLocksParsed;
|
|
|
|
|
2023-04-02 20:57:17 +03:00
|
|
|
lockPackages = flatten (map unique (attrValues (groupBy
|
|
|
|
(p: "${p.name}:${p.version}:${p.source or "local-path"}")
|
2023-04-03 02:46:24 +03:00
|
|
|
(flatten allPackagesTrimmed)
|
2023-04-02 20:57:17 +03:00
|
|
|
)));
|
|
|
|
|
|
|
|
vendoredRegistries = vendorCargoRegistries ({
|
|
|
|
inherit cargoConfigs lockPackages;
|
2024-03-05 06:53:19 +03:00
|
|
|
} // optionalAttrs (registries != null) { inherit registries; });
|
2023-04-02 20:57:17 +03:00
|
|
|
|
|
|
|
vendoredGit = vendorGitDeps {
|
2023-09-22 07:08:53 +03:00
|
|
|
inherit lockPackages outputHashes;
|
2023-04-02 20:57:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
linkSources = sources: concatMapStrings
|
|
|
|
(name: ''
|
|
|
|
ln -s ${escapeShellArg sources.${name}} $out/${escapeShellArg name}
|
|
|
|
'')
|
|
|
|
(attrNames sources);
|
|
|
|
in
|
|
|
|
runCommandLocal "vendor-cargo-deps" { } ''
|
|
|
|
mkdir -p $out
|
|
|
|
cat >>$out/config.toml <<EOF
|
|
|
|
${vendoredRegistries.config}
|
|
|
|
${vendoredGit.config}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
${linkSources vendoredRegistries.sources}
|
|
|
|
${linkSources vendoredGit.sources}
|
|
|
|
''
|