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