{ lib, stdenv, fetchurl, fetchFromGitHub, python, makeWrapper, unzip, pipInstallHookMine, setuptoolsBuildHook, wheel, pip, setuptools, breakpointHook }: let pipBootstrap = (fetchurl { url = "https://files.pythonhosted.org/packages/b6/ac/7015eb97dc749283ffdec1c3a88ddb8ae03b8fad0f0e611408f196358da3/pip-9.0.1-py2.py3-none-any.whl"; sha256 = "690b762c0a8460c303c089d5d0be034fb15a5ea2b75bdf565f40421f542fefb0"; }); argparse = fetchFromGitHub { pname = "argparse"; version = "1.4.0"; owner="ThomasWaldmann"; repo ="argparse"; tag = "r140"; hash = "sha256-L0cJ44aO3Wd2P/8vykJlOEZu7W2AsNCcAaGDeHtn6b0="; }; in stdenv.mkDerivation rec { pname = "pip"; inherit (pip) version; name = "${python.libPrefix}-bootstrapped-${pname}-${version}"; srcs = [ wheel.src pip.src setuptools.src argparse ]; sourceRoot = "."; dontUseSetuptoolsBuild = true; dontUsePipInstall = true; # Should be propagatedNativeBuildInputs propagatedBuildInputs = [ # Override to remove dependencies to prevent infinite recursion. (pipInstallHookMine.override { pip = null; }) (setuptoolsBuildHook.override { setuptools = null; wheel = null; }) ]; postPatch = '' mkdir -p $out/bin ''; nativeBuildInputs = [ makeWrapper unzip breakpointHook ]; buildInputs = [ python ]; dontBuild = true; installPhase = lib.optionalString (!stdenv.hostPlatform.isWindows) '' export SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES=0 '' + '' echo '#!${python.interpreter}' > hostPip echo 'import sys;from pip import main' >> hostPip echo 'sys.exit(main())' >> hostPip chmod +x hostPip # Give folders a known name mv pip* pip mv setuptools* setuptools mv wheel* wheel mv argparse* argparse # Set up PYTHONPATH: # - pip and setuptools need to be in PYTHONPATH to install setuptools, wheel, and pip. # - $out is where we are installing to and takes precedence, and is where wheel will end so we can install pip. export PYTHONPATH="$out/${python.sitePackages}:$(pwd)/pip/pip:$(pwd)/setuptools:$(pwd)/setuptools/pkg_resources:$PYTHONPATH" echo "Building setuptools wheel..." pushd setuptools ${python.pythonOnBuildForHost.interpreter} ${pipBootstrap}/pip install --no-index --prefix=$out --ignore-installed --no-dependencies --no-cache . popd echo "Building wheel wheel..." pushd wheel ${python.pythonOnBuildForHost.interpreter} ${pipBootstrap}/pip install --no-index --prefix=$out --ignore-installed --no-dependencies --no-cache . popd echo "Building pip wheel..." pushd pip ${python.pythonOnBuildForHost.interpreter} ${pipBootstrap}/pip install --no-index --prefix=$out --ignore-installed --no-dependencies --no-cache . popd echo "Building argparse wheel..." pushd argparse ${python.pythonOnBuildForHost.interpreter} ${pipBootstrap}/pip install --prefix=$out --no-cache . popd ''; meta = { description = "Version of pip used for bootstrapping"; license = lib.unique (pip.meta.license ++ setuptools.meta.license ++ wheel.meta.license); homepage = pip.meta.homepage; }; }