1{ lib, stdenv, python, makeWrapper, unzip
2, pipInstallHook
3, setuptoolsBuildHook
4, wheel, pip, setuptools
5}:
6
7stdenv.mkDerivation rec {
8 pname = "pip";
9 inherit (pip) version;
10 name = "${python.libPrefix}-bootstrapped-${pname}-${version}";
11
12 srcs = [ wheel.src pip.src setuptools.src ];
13 sourceRoot = ".";
14
15 dontUseSetuptoolsBuild = true;
16 dontUsePipInstall = true;
17
18 # Should be propagatedNativeBuildInputs
19 propagatedBuildInputs = [
20 # Override to remove dependencies to prevent infinite recursion.
21 (pipInstallHook.override{pip=null;})
22 (setuptoolsBuildHook.override{setuptools=null; wheel=null;})
23 ];
24
25 postPatch = ''
26 mkdir -p $out/bin
27 '' + (pip.postPatch or ""); # `pip` does not necessarily have a `postPatch` field.
28
29 nativeBuildInputs = [ makeWrapper unzip ];
30 buildInputs = [ python ];
31
32 dontBuild = true;
33
34 installPhase = lib.optionalString (!stdenv.hostPlatform.isWindows) ''
35 export SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES=0
36 '' + ''
37 # Give folders a known name
38 mv pip* pip
39 mv setuptools* setuptools
40 mv wheel* wheel
41 # Set up PYTHONPATH. The above folders need to be on PYTHONPATH
42 # $out is where we are installing to and takes precedence
43 export PYTHONPATH="$out/${python.sitePackages}:$(pwd)/pip/src:$(pwd)/setuptools:$(pwd)/setuptools/pkg_resources:$(pwd)/wheel:$PYTHONPATH"
44
45 echo "Building setuptools wheel..."
46 pushd setuptools
47 rm pyproject.toml
48 ${python.pythonForBuild.interpreter} -m pip install --no-build-isolation --no-index --prefix=$out --ignore-installed --no-dependencies --no-cache .
49 popd
50
51 echo "Building wheel wheel..."
52 pushd wheel
53 ${python.pythonForBuild.interpreter} -m pip install --no-build-isolation --no-index --prefix=$out --ignore-installed --no-dependencies --no-cache .
54 popd
55
56 echo "Building pip wheel..."
57 pushd pip
58 rm pyproject.toml
59 ${python.pythonForBuild.interpreter} -m pip install --no-build-isolation --no-index --prefix=$out --ignore-installed --no-dependencies --no-cache .
60 popd
61 '';
62
63 meta = {
64 description = "Version of pip used for bootstrapping";
65 license = lib.unique (pip.meta.license ++ setuptools.meta.license ++ wheel.meta.license);
66 homepage = pip.meta.homepage;
67 };
68}