crane/lib/downloadCargoPackage.nix

45 lines
776 B
Nix
Raw Normal View History

{ pkgsBuildBuild
2021-12-27 01:05:23 +03:00
, urlForCargoPackage
}:
let
inherit (pkgsBuildBuild)
fetchurl
stdenv;
in
2021-12-27 01:05:23 +03:00
{ name
, version
, checksum
, ...
}@args:
2021-12-27 01:05:23 +03:00
let
pkgInfo = urlForCargoPackage args;
tarball = fetchurl (pkgInfo.fetchurlExtraArgs // {
inherit (pkgInfo) url;
2021-12-27 01:05:23 +03:00
name = "${name}-${version}";
sha256 = checksum;
});
2021-12-27 01:05:23 +03:00
in
stdenv.mkDerivation {
inherit version;
pname = "cargo-package-${name}";
dontConfigure = true;
dontBuild = true;
unpackPhase = ''
runHook preUnpack
mkdir -p crate
tar -xzf ${tarball} --strip-components=1
runHook postUnpack
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r -t $out .
echo '{"files":{}, "package":"${checksum}"}' > $out/.cargo-checksum.json
runHook postInstall
'';
}