mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-27 09:23:01 +00:00
923c9f62c4
This enables short argument attrsets similar to fetchPypi: src = fetchCrate { inherit pname version; sha256 = "02h8pikmk19ziqw9jgxxf7kjhnb3792vz9is446p1xfvlh4mzmyx"; };
39 lines
928 B
Nix
39 lines
928 B
Nix
{ lib, fetchurl, unzip }:
|
|
|
|
{ crateName ? args.pname
|
|
, pname ? null
|
|
, version
|
|
, sha256
|
|
, ... } @ args:
|
|
|
|
assert pname == null || pname == crateName;
|
|
|
|
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" "pname" "version" ]))
|
|
# Hackety-hack: we actually need unzip hooks, too
|
|
(x: {nativeBuildInputs = x.nativeBuildInputs++ [unzip];})
|