1{ stdenv, python, fetchurl, makeWrapper, unzip }:
2
3let
4 wheel_source = fetchurl {
5 url = "https://pypi.python.org/packages/py2.py3/w/wheel/wheel-0.29.0-py2.py3-none-any.whl";
6 sha256 = "ea8033fc9905804e652f75474d33410a07404c1a78dd3c949a66863bd1050ebd";
7 };
8 setuptools_source = fetchurl {
9 url = "https://pypi.python.org/packages/3.5/s/setuptools/setuptools-19.4-py2.py3-none-any.whl";
10 sha256 = "0801e6d862ca4ce24d918420d62f07ee2fe736dc016e3afa99d2103e7a02e9a6";
11 };
12 argparse_source = fetchurl {
13 url = "https://pypi.python.org/packages/2.7/a/argparse/argparse-1.4.0-py2.py3-none-any.whl";
14 sha256 = "0533cr5w14da8wdb2q4py6aizvbvsdbk3sj7m1jx9lwznvnlf5n3";
15 };
16in stdenv.mkDerivation rec {
17 name = "python-${python.version}-bootstrapped-pip-${version}";
18 version = "8.0.2";
19
20 src = fetchurl {
21 url = "https://pypi.python.org/packages/py2.py3/p/pip/pip-${version}-py2.py3-none-any.whl";
22 sha256 = "249a6f3194be8c2e8cb4d4be3f6fd16a9f1e3336218caffa8e7419e3816f9988";
23 };
24
25 unpackPhase = ''
26 mkdir -p $out/${python.sitePackages}
27 unzip -d $out/${python.sitePackages} $src
28 unzip -d $out/${python.sitePackages} ${setuptools_source}
29 unzip -d $out/${python.sitePackages} ${wheel_source}
30 '' + stdenv.lib.optionalString (python.isPy26 or false) ''
31 unzip -d $out/${python.sitePackages} ${argparse_source}
32 '';
33
34
35 patchPhase = ''
36 mkdir -p $out/bin
37 '';
38
39 buildInputs = [ python makeWrapper unzip ];
40
41 installPhase = ''
42
43 # install pip binary
44 echo '#!${python.interpreter}' > $out/bin/pip
45 echo 'import sys;from pip import main' >> $out/bin/pip
46 echo 'sys.exit(main())' >> $out/bin/pip
47 chmod +x $out/bin/pip
48
49 # wrap binaries with PYTHONPATH
50 for f in $out/bin/*; do
51 wrapProgram $f --prefix PYTHONPATH ":" $out/${python.sitePackages}/
52 done
53 '';
54}