nixpkgs/pkgs/development/tools/pypi2nix/default.nix

107 lines
2.8 KiB
Nix
Raw Normal View History

{ stdenv, fetchFromGitHub, fetchurl, pythonPackages, zip, makeWrapper, nix, nix-prefetch-git
2017-04-11 13:12:26 +02:00
, nix-prefetch-hg
2016-05-07 05:04:25 +02:00
}:
let
2016-09-25 04:42:23 +02:00
version = "1.8.1";
2016-09-25 04:42:23 +02:00
src = fetchFromGitHub {
owner = "garbas";
repo = "pypi2nix";
rev = "v${version}";
sha256 = "039a2ys7ijzi2sa2haa6a8lbhncvd1wfsi6gcy9vm02gi31ghzyb";
2016-09-25 04:42:23 +02:00
};
click = fetchurl {
2017-04-11 13:12:26 +02:00
url = "https://pypi.python.org/packages/95/d9/c3336b6b5711c3ab9d1d3a80f1a3e2afeb9d8c02a7166462f6cc96570897/click-6.7.tar.gz";
sha256 = "02qkfpykbq35id8glfgwc38yc430427yd05z1wc5cnld8zgicmgi";
2016-05-07 05:04:25 +02:00
};
2016-09-25 04:42:23 +02:00
requests = fetchurl {
2017-04-11 13:12:26 +02:00
url = "https://pypi.python.org/packages/16/09/37b69de7c924d318e51ece1c4ceb679bf93be9d05973bb30c35babd596e2/requests-2.13.0.tar.gz";
sha256 = "1s0wg4any4dsv5l3hqjxqk2zgb7pdbqhy9rhc8kh3aigfq4ws8jp";
2016-09-25 04:42:23 +02:00
};
2016-05-07 05:04:25 +02:00
in stdenv.mkDerivation rec {
name = "pypi2nix-${version}";
2016-09-25 04:42:23 +02:00
srcs = [
2016-07-25 04:25:51 +02:00
src
click
requests
2016-09-25 04:42:23 +02:00
];
2017-04-11 13:12:26 +02:00
buildInputs = [
pythonPackages.python pythonPackages.flake8
zip makeWrapper nix.out nix-prefetch-git nix-prefetch-hg
];
2016-05-07 05:04:25 +02:00
sourceRoot = ".";
postUnpack = ''
mkdir -p $out/pkgs
mv click-*/click $out/pkgs/click
2016-07-25 04:25:51 +02:00
mv requests-*/requests $out/pkgs/
2016-05-07 05:04:25 +02:00
2016-08-15 03:46:43 +02:00
if [ "$IN_NIX_SHELL" != "1" ]; then
2016-05-07 05:04:25 +02:00
if [ -e git-export ]; then
mv git-export/src/pypi2nix $out/pkgs/pypi2nix
else
2017-11-02 07:11:06 +01:00
mv source/src/pypi2nix $out/pkgs/pypi2nix
2016-05-07 05:04:25 +02:00
fi
fi
'';
2016-12-23 23:44:45 +01:00
patchPhase = ''
sed -i -e "s|default='nix-shell',|default='${nix.out}/bin/nix-shell',|" $out/pkgs/pypi2nix/cli.py
2017-04-11 13:12:26 +02:00
sed -i -e "s|nix-prefetch-git|${nix-prefetch-git}/bin/nix-prefetch-git|" $out/pkgs/pypi2nix/stage2.py
sed -i -e "s|nix-prefetch-hg|${nix-prefetch-hg}/bin/nix-prefetch-hg|" $out/pkgs/pypi2nix/stage2.py
2016-12-23 23:44:45 +01:00
'';
2016-05-07 05:04:25 +02:00
commonPhase = ''
mkdir -p $out/bin
2017-04-11 13:12:26 +02:00
echo "#!${pythonPackages.python.interpreter}" > $out/bin/pypi2nix
2016-08-15 03:46:43 +02:00
echo "import pypi2nix.cli" >> $out/bin/pypi2nix
echo "pypi2nix.cli.main()" >> $out/bin/pypi2nix
2016-05-07 05:04:25 +02:00
chmod +x $out/bin/pypi2nix
export PYTHONPATH=$out/pkgs:$PYTHONPATH
'';
2017-04-11 13:12:26 +02:00
# flake8 doesn't run on python3
doCheck = false;
checkPhase = ''
flake8 ${src}/src
'';
2016-05-07 05:04:25 +02:00
installPhase = commonPhase + ''
2017-04-11 13:12:26 +02:00
wrapProgram $out/bin/pypi2nix \
--prefix PYTHONPATH : "$PYTHONPATH" \
--prefix PATH : "${nix-prefetch-git}/bin:${nix-prefetch-hg}/bin"
2016-05-07 05:04:25 +02:00
'';
shellHook = ''
export home=`pwd`
export out=/tmp/`pwd | md5sum | cut -f 1 -d " "`-$name
rm -rf $out
mkdir -p $out
cd $out
runHook unpackPhase
runHook commonPhase
cd $home
export PATH=$out/bin:$PATH
export PYTHONPATH=`pwd`/src:$PYTHONPATH
'';
2016-06-29 01:48:38 +02:00
2016-05-07 05:04:25 +02:00
meta = {
homepage = https://github.com/garbas/pypi2nix;
description = "A tool that generates nix expressions for your python packages, so you don't have to.";
maintainers = with stdenv.lib.maintainers; [ garbas ];
};
}