mirror of
https://github.com/ipetkov/crane.git
synced 2024-11-27 02:52:02 +03:00
f8d1e70dfc
* When Nix fetches a git repo it will only look for the specified revision only starting from the main branch (apparently fetching arbitrary revisions from a repository has some security implications) * If a ref (i.e. branch or tag) is not specified, Nix will only fetch the repo's main branch * To remedy this we will supply Nix with the branch or tag (if specified in the Cargo.lock) to help it find the specified revision * If cargo does not specify a branch or tag for us, we'll set `allRefs = true` so that Nix can try fetching all possible branches and tags before trying to check out the locked revision
44 lines
842 B
Nix
44 lines
842 B
Nix
{ cargo
|
|
, jq
|
|
, lib
|
|
, remarshal
|
|
, runCommandLocal
|
|
}:
|
|
|
|
{ git
|
|
, rev
|
|
, ref ? null
|
|
, allRefs ? ref == null
|
|
}@args:
|
|
let
|
|
maybeRef = lib.optionalAttrs (ref != null) { inherit ref; };
|
|
repo = builtins.fetchGit (maybeRef // {
|
|
inherit allRefs rev;
|
|
url = git;
|
|
submodules = true;
|
|
});
|
|
|
|
deps = {
|
|
nativeBuildInputs = [
|
|
cargo
|
|
jq
|
|
remarshal
|
|
];
|
|
};
|
|
in
|
|
runCommandLocal "cargo-git" deps ''
|
|
mkdir -p $out
|
|
while read -r cargoToml; do
|
|
local crate=$(toml2json <"$cargoToml" | \
|
|
jq -r 'select(.package != null) | .package | "\(.name)-\(.version)"'
|
|
)
|
|
|
|
if [ -n "$crate" ]; then
|
|
local dest="$out/$crate"
|
|
cp -r "$(dirname "$cargoToml")" "$dest"
|
|
chmod +w "$dest"
|
|
echo '{"files":{}, "package":null}' > "$dest/.cargo-checksum.json"
|
|
fi
|
|
done < <(find ${repo} -name Cargo.toml)
|
|
''
|