From aedbade43e615d7893d268632f5e7f2570fd3233 Mon Sep 17 00:00:00 2001 From: misuzu Date: Mon, 22 Jun 2020 10:58:26 +0300 Subject: [PATCH] python3Packages.pip: allow setting reproducible temporary directory via NIX_PIP_INSTALL_TMPDIR --- .../interpreters/python/hooks/pip-install-hook.sh | 4 +++- pkgs/development/python-modules/pip/default.nix | 4 ++++ .../python-modules/pip/reproducible.patch | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/python-modules/pip/reproducible.patch diff --git a/pkgs/development/interpreters/python/hooks/pip-install-hook.sh b/pkgs/development/interpreters/python/hooks/pip-install-hook.sh index 4eefe22d3f28..770739b36bde 100644 --- a/pkgs/development/interpreters/python/hooks/pip-install-hook.sh +++ b/pkgs/development/interpreters/python/hooks/pip-install-hook.sh @@ -11,7 +11,9 @@ pipInstallPhase() { export PYTHONPATH="$out/@pythonSitePackages@:$PYTHONPATH" pushd dist || return 1 - @pythonInterpreter@ -m pip install ./*.whl --no-index --prefix="$out" --no-cache $pipInstallFlags --build tmpbuild + mkdir tmpbuild + NIX_PIP_INSTALL_TMPDIR=tmpbuild @pythonInterpreter@ -m pip install ./*.whl --no-index --prefix="$out" --no-cache $pipInstallFlags + rm -rf tmpbuild popd || return 1 runHook postInstall diff --git a/pkgs/development/python-modules/pip/default.nix b/pkgs/development/python-modules/pip/default.nix index e4ace129d996..fa566c8951ab 100644 --- a/pkgs/development/python-modules/pip/default.nix +++ b/pkgs/development/python-modules/pip/default.nix @@ -25,6 +25,10 @@ buildPythonPackage rec { name = "${pname}-${version}-source"; }; + # Remove when solved https://github.com/NixOS/nixpkgs/issues/81441 + # Also update pkgs/development/interpreters/python/hooks/pip-install-hook.sh accordingly + patches = [ ./reproducible.patch ]; + nativeBuildInputs = [ bootstrapped-pip ]; # pip detects that we already have bootstrapped_pip "installed", so we need diff --git a/pkgs/development/python-modules/pip/reproducible.patch b/pkgs/development/python-modules/pip/reproducible.patch new file mode 100644 index 000000000000..528ac2b49b03 --- /dev/null +++ b/pkgs/development/python-modules/pip/reproducible.patch @@ -0,0 +1,13 @@ +diff --git a/src/pip/_internal/operations/install/wheel.py b/src/pip/_internal/operations/install/wheel.py +index e7315ee4..4e36b03d 100644 +--- a/src/pip/_internal/operations/install/wheel.py ++++ b/src/pip/_internal/operations/install/wheel.py +@@ -615,6 +615,8 @@ def install_wheel( + direct_url=None, # type: Optional[DirectUrl] + ): + # type: (...) -> None ++ _temp_dir_for_testing = ( ++ _temp_dir_for_testing or os.environ.get("NIX_PIP_INSTALL_TMPDIR")) + with TempDirectory( + path=_temp_dir_for_testing, kind="unpacked-wheel" + ) as unpacked_dir, ZipFile(wheel_path, allowZip64=True) as z: