2024-01-28 22:08:44 +03:00
|
|
|
{ lib
|
2024-06-03 05:48:19 +03:00
|
|
|
, cargo
|
2024-06-29 21:29:52 +03:00
|
|
|
, craneUtils
|
2024-06-03 05:48:19 +03:00
|
|
|
, jq
|
2024-01-28 22:08:44 +03:00
|
|
|
, pkgsBuildBuild
|
2022-02-08 07:03:12 +03:00
|
|
|
}:
|
|
|
|
|
2024-01-28 22:08:44 +03:00
|
|
|
let
|
|
|
|
inherit (pkgsBuildBuild)
|
|
|
|
fetchgit
|
2024-05-19 02:39:46 +03:00
|
|
|
stdenv;
|
2024-01-28 22:08:44 +03:00
|
|
|
in
|
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
|
2023-09-22 07:08:53 +03:00
|
|
|
, sha256 ? null
|
2022-02-19 04:46:05 +03:00
|
|
|
, 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; };
|
2023-09-22 07:08:53 +03:00
|
|
|
repo =
|
|
|
|
if sha256 == null then
|
|
|
|
builtins.fetchGit
|
|
|
|
(maybeRef // {
|
|
|
|
inherit allRefs rev;
|
|
|
|
url = git;
|
|
|
|
submodules = true;
|
|
|
|
})
|
|
|
|
else
|
|
|
|
fetchgit {
|
|
|
|
inherit rev sha256;
|
|
|
|
url = git;
|
|
|
|
fetchSubmodules = true;
|
|
|
|
};
|
2022-02-08 07:03:12 +03:00
|
|
|
in
|
2024-05-19 02:39:46 +03:00
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "cargo-git";
|
|
|
|
src = repo;
|
2022-02-11 07:32:31 +03:00
|
|
|
|
2024-05-19 02:39:46 +03:00
|
|
|
dontConfigure = true;
|
|
|
|
dontBuild = true;
|
2024-05-20 00:59:49 +03:00
|
|
|
dontFixup = true;
|
2024-05-19 02:39:46 +03:00
|
|
|
|
2024-06-03 05:48:19 +03:00
|
|
|
depsBuildBuild = [
|
2024-05-19 02:39:46 +03:00
|
|
|
cargo
|
|
|
|
craneUtils
|
|
|
|
jq
|
|
|
|
];
|
2022-11-10 05:12:34 +03:00
|
|
|
|
2024-05-19 02:39:46 +03:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
2022-11-10 05:12:34 +03:00
|
|
|
|
2024-05-19 02:39:46 +03:00
|
|
|
mkdir -p $out
|
|
|
|
declare -A existing_crates
|
|
|
|
find "$(pwd)" -name Cargo.toml | while read -r cargoToml; do
|
|
|
|
local crate=$(
|
|
|
|
cargo metadata --format-version 1 --no-deps --manifest-path "$cargoToml" |
|
|
|
|
jq -r '.packages[] | select(.manifest_path == "'"$cargoToml"'") | "\(.name)-\(.version)"'
|
|
|
|
)
|
|
|
|
|
|
|
|
if [ -n "$crate" ]; then
|
|
|
|
if [[ -n "''${existing_crates["$crate"]}" ]]; then
|
|
|
|
>&2 echo "warning: skipping duplicate package $crate found at $cargoToml"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
local dest="$out/$crate"
|
|
|
|
cp -rL "$(dirname "$cargoToml")" "$dest"
|
|
|
|
chmod +w "$dest"
|
|
|
|
echo '{"files":{}, "package":null}' > "$dest/.cargo-checksum.json"
|
|
|
|
|
|
|
|
crane-resolve-workspace-inheritance "$cargoToml" > "$dest/Cargo.toml.resolved" &&
|
|
|
|
mv "$dest/Cargo.toml"{.resolved,}
|
|
|
|
|
|
|
|
existing_crates["$crate"]='1'
|
|
|
|
fi
|
|
|
|
done
|
2023-01-22 03:46:32 +03:00
|
|
|
|
2024-05-19 02:39:46 +03:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
}
|