crane/lib/downloadCargoPackage.nix
Ivan Petkov 8b4f7a4dab
various: switch to using runCommand to improve caching (#384)
For example, commands which extract a tarball should be cached (i.e
should use `runCommand` not `runCommandLocal`) because it allows builds
to download the unpacked result instead of having to write both to the
store
2023-09-04 00:33:25 +00:00

24 lines
475 B
Nix

{ fetchurl
, urlForCargoPackage
, runCommand
}:
{ name
, version
, checksum
, ...
}@args:
let
pkgInfo = urlForCargoPackage args;
tarball = fetchurl (pkgInfo.fetchurlExtraArgs // {
inherit (pkgInfo) url;
name = "${name}-${version}";
sha256 = checksum;
});
in
runCommand "cargo-package-${name}-${version}" { } ''
mkdir -p $out
tar -xzf ${tarball} -C $out --strip-components=1
echo '{"files":{}, "package":"${checksum}"}' > $out/.cargo-checksum.json
''