1{ stdenv, python, fetchPypi, fetchurl, makeWrapper, unzip }:
2
3let
4 wheel_source = fetchPypi {
5 pname = "wheel";
6 version = "0.30.0";
7 format = "wheel";
8 sha256 = "e721e53864f084f956f40f96124a74da0631ac13fbbd1ba99e8e2b5e9cafdf64";
9 };
10 setuptools_source = fetchPypi {
11 pname = "setuptools";
12 version = "38.4.0";
13 format = "wheel";
14 sha256 = "155c2ec9fdcc00c3973d966b416e1cf3a1e7ce75f4c09fb760b23f94b935926e";
15 };
16
17 # TODO: Shouldn't be necessary anymore for pip > 9.0.1!
18 # https://github.com/NixOS/nixpkgs/issues/26392
19 # https://github.com/pypa/setuptools/issues/885
20 pkg_resources = fetchurl {
21 url = "https://raw.githubusercontent.com/pypa/setuptools/v36.0.1/pkg_resources/__init__.py";
22 sha256 = "1wdnq3mammk75mifkdmmjx7yhnpydvnvi804na8ym4mj934l2jkv";
23 };
24
25in stdenv.mkDerivation rec {
26 pname = "pip";
27 version = "9.0.1";
28 name = "${python.libPrefix}-bootstrapped-${pname}-${version}";
29
30 src = fetchPypi {
31 inherit pname version;
32 format = "wheel";
33 sha256 = "690b762c0a8460c303c089d5d0be034fb15a5ea2b75bdf565f40421f542fefb0";
34 };
35
36 unpackPhase = ''
37 mkdir -p $out/${python.sitePackages}
38 unzip -d $out/${python.sitePackages} $src
39 unzip -d $out/${python.sitePackages} ${setuptools_source}
40 unzip -d $out/${python.sitePackages} ${wheel_source}
41 # TODO: Shouldn't be necessary anymore for pip > 9.0.1!
42 cp ${pkg_resources} $out/${python.sitePackages}/pip/_vendor/pkg_resources/__init__.py
43 '';
44
45 patchPhase = ''
46 mkdir -p $out/bin
47 '';
48
49 nativeBuildInputs = [ makeWrapper unzip ];
50 buildInputs = [ python ];
51
52 installPhase = ''
53
54 # install pip binary
55 echo '#!${python.interpreter}' > $out/bin/pip
56 echo 'import sys;from pip import main' >> $out/bin/pip
57 echo 'sys.exit(main())' >> $out/bin/pip
58 chmod +x $out/bin/pip
59
60 # wrap binaries with PYTHONPATH
61 for f in $out/bin/*; do
62 wrapProgram $f --prefix PYTHONPATH ":" $out/${python.sitePackages}/
63 done
64 '';
65}