add fetchCrate function to fetch rust crates

This commit is contained in:
Pierre-Étienne Meunier 2017-12-12 04:54:01 -06:00 committed by Jörg Thalheim
parent a13fc5f4cc
commit ea232fe29d
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,35 @@
{ lib, fetchurl, unzip }:
{ crateName
, version
, sha256
, ... } @ args:
lib.overrideDerivation (fetchurl ({
name = "${crateName}-${version}.tar.gz";
url = "https://crates.io/api/v1/crates/${crateName}/${version}/download";
recursiveHash = true;
downloadToTemp = true;
postFetch =
''
export PATH=${unzip}/bin:$PATH
unpackDir="$TMPDIR/unpack"
mkdir "$unpackDir"
cd "$unpackDir"
renamed="$TMPDIR/${crateName}-${version}.tar.gz"
mv "$downloadedFile" "$renamed"
unpackFile "$renamed"
fn=$(cd "$unpackDir" && echo *)
if [ -f "$unpackDir/$fn" ]; then
mkdir $out
fi
mv "$unpackDir/$fn" "$out"
'';
} // removeAttrs args [ "crateName" "version" ]))
# Hackety-hack: we actually need unzip hooks, too
(x: {nativeBuildInputs = x.nativeBuildInputs++ [unzip];})

View File

@ -202,6 +202,8 @@ with pkgs;
fetchzip = callPackage ../build-support/fetchzip { };
fetchCrate = callPackage ../build-support/rust/fetchcrate.nix { };
fetchFromGitHub = {
owner, repo, rev, name ? "source",
fetchSubmodules ? false, private ? false,