2022-02-11 07:32:31 +03:00
|
|
|
{ cargo
|
|
|
|
, jq
|
2022-02-19 04:46:05 +03:00
|
|
|
, lib
|
2022-02-11 07:32:31 +03:00
|
|
|
, remarshal
|
|
|
|
, runCommandLocal
|
2022-02-08 07:03:12 +03:00
|
|
|
}:
|
|
|
|
|
2022-02-11 07:32:31 +03:00
|
|
|
{ git
|
2022-02-08 07:03:12 +03:00
|
|
|
, rev
|
2022-02-19 04:46:05 +03:00
|
|
|
, ref ? null
|
|
|
|
, allRefs ? ref == null
|
2022-10-24 02:20:22 +03:00
|
|
|
}:
|
2022-02-08 07:03:12 +03:00
|
|
|
let
|
2022-02-19 04:46:05 +03:00
|
|
|
maybeRef = lib.optionalAttrs (ref != null) { inherit ref; };
|
|
|
|
repo = builtins.fetchGit (maybeRef // {
|
|
|
|
inherit allRefs rev;
|
2022-02-08 07:03:12 +03:00
|
|
|
url = git;
|
|
|
|
submodules = true;
|
2022-02-19 04:46:05 +03:00
|
|
|
});
|
2022-02-11 07:32:31 +03:00
|
|
|
|
|
|
|
deps = {
|
|
|
|
nativeBuildInputs = [
|
|
|
|
cargo
|
|
|
|
jq
|
|
|
|
remarshal
|
|
|
|
];
|
|
|
|
};
|
2022-02-08 07:03:12 +03:00
|
|
|
in
|
2022-02-11 07:32:31 +03:00
|
|
|
runCommandLocal "cargo-git" deps ''
|
|
|
|
mkdir -p $out
|
2022-11-10 05:12:34 +03:00
|
|
|
existing_crates=()
|
2022-02-11 07:32:31 +03:00
|
|
|
while read -r cargoToml; do
|
|
|
|
local crate=$(toml2json <"$cargoToml" | \
|
|
|
|
jq -r 'select(.package != null) | .package | "\(.name)-\(.version)"'
|
|
|
|
)
|
|
|
|
|
|
|
|
if [ -n "$crate" ]; then
|
2022-11-10 05:12:34 +03:00
|
|
|
if [[ " ''${existing_crates[*]} " =~ " $crate " ]]; then
|
|
|
|
>&2 echo "warning: skipping duplicate package $crate found at $cargoToml"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2022-02-11 07:32:31 +03:00
|
|
|
local dest="$out/$crate"
|
|
|
|
cp -r "$(dirname "$cargoToml")" "$dest"
|
|
|
|
chmod +w "$dest"
|
|
|
|
echo '{"files":{}, "package":null}' > "$dest/.cargo-checksum.json"
|
2022-11-10 05:12:34 +03:00
|
|
|
|
|
|
|
existing_crates+=("$crate")
|
2022-02-11 07:32:31 +03:00
|
|
|
fi
|
|
|
|
done < <(find ${repo} -name Cargo.toml)
|
2022-02-08 07:03:12 +03:00
|
|
|
''
|