1{ stdenv, python, fetchPypi, makeWrapper, unzip }:
2
3let
4 wheel_source = fetchPypi {
5 pname = "wheel";
6 version = "0.31.1";
7 format = "wheel";
8 sha256 = "80044e51ec5bbf6c894ba0bc48d26a8c20a9ba629f4ca19ea26ecfcf87685f5f";
9 };
10 setuptools_source = fetchPypi {
11 pname = "setuptools";
12 version = "40.2.0";
13 format = "wheel";
14 sha256 = "ea3796a48a207b46ea36a9d26de4d0cc87c953a683a7b314ea65d666930ea8e6";
15 };
16
17in stdenv.mkDerivation rec {
18 pname = "pip";
19 version = "18.0";
20 name = "${python.libPrefix}-bootstrapped-${pname}-${version}";
21
22 src = fetchPypi {
23 inherit pname version;
24 format = "wheel";
25 sha256 = "070e4bf493c7c2c9f6a08dd797dd3c066d64074c38e9e8a0fb4e6541f266d96c";
26 };
27
28 unpackPhase = ''
29 mkdir -p $out/${python.sitePackages}
30 unzip -d $out/${python.sitePackages} $src
31 unzip -d $out/${python.sitePackages} ${setuptools_source}
32 unzip -d $out/${python.sitePackages} ${wheel_source}
33 '';
34
35 patchPhase = ''
36 mkdir -p $out/bin
37 '';
38
39 nativeBuildInputs = [ makeWrapper unzip ];
40 buildInputs = [ python ];
41
42 installPhase = ''
43
44 # install pip binary
45 echo '#!${python.interpreter}' > $out/bin/pip
46 echo 'import sys;from pip._internal import main' >> $out/bin/pip
47 echo 'sys.exit(main())' >> $out/bin/pip
48 chmod +x $out/bin/pip
49
50 # wrap binaries with PYTHONPATH
51 for f in $out/bin/*; do
52 wrapProgram $f --prefix PYTHONPATH ":" $out/${python.sitePackages}/
53 done
54 '';
55}