Python: set DETERMINISTIC_BUILD and PYTHONHASHSEED in setupHook

The Python interpreters are patched so they can build .pyc bytecode free
of certain indeterminism.

When building Python packages we currently set

```
compiling python files.
in nix store.
DETERMINISTIC_BUILD=1;
PYTHONHASHSEED = 0;
```

Instead if setting these environment variables in the function that
builds the package, this commit sets the variables instead in the Python
setup hook. That way, whenever Python is included in a derivation, these
variables are set.

See also the issue https://github.com/NixOS/nixpkgs/issues/25707.
This commit is contained in:
Frederik Rietdijk
2017-05-19 14:21:58 +02:00
parent 5aa530f2a8
commit acd32a4caf
16 changed files with 50 additions and 105 deletions

View File

@@ -15,6 +15,7 @@
, expat
, libffi
, CF, configd, coreutils
, python-setup-hook
# For the Python package set
, pkgs, packageOverrides ? (self: super: {})
}:
@@ -150,7 +151,7 @@ in stdenv.mkDerivation {
NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin "-msse2";
DETERMINISTIC_BUILD = 1;
setupHook = ./setup-hook.sh;
setupHook = python-setup-hook sitePackages;
postPatch = optionalString (x11Support && (tix != null)) ''
substituteInPlace "Lib/lib-tk/Tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tix}/lib'"

View File

@@ -1,15 +0,0 @@
addPythonPath() {
addToSearchPathWithCustomDelimiter : PYTHONPATH $1/lib/python2.7/site-packages
}
toPythonPath() {
local paths="$1"
local result=
for i in $paths; do
p="$i/lib/python2.7/site-packages"
result="${result}${result:+:}$p"
done
echo $result
}
envHooks+=(addPythonPath)

View File

@@ -77,7 +77,7 @@ in stdenv.mkDerivation {
)
'';
setupHook = ./setup-hook.sh;
setupHook = python-setup-hook sitePackages;
postInstall = ''
# needed for some packages, especially packages that backport functionality

View File

@@ -1,15 +0,0 @@
addPythonPath() {
addToSearchPathWithCustomDelimiter : PYTHONPATH $1/lib/python3.3/site-packages
}
toPythonPath() {
local paths="$1"
local result=
for i in $paths; do
p="$i/lib/python3.3/site-packages"
result="${result}${result:+:}$p"
done
echo $result
}
envHooks+=(addPythonPath)

View File

@@ -13,6 +13,7 @@
, callPackage
, self
, CF, configd
, python-setup-hook
# For the Python package set
, pkgs, packageOverrides ? (self: super: {})
}:
@@ -100,7 +101,7 @@ in stdenv.mkDerivation {
''}
'';
setupHook = ./setup-hook.sh;
setupHook = python-setup-hook sitePackages;
postInstall = ''
# needed for some packages, especially packages that backport functionality

View File

@@ -1,15 +0,0 @@
addPythonPath() {
addToSearchPathWithCustomDelimiter : PYTHONPATH $1/lib/python3.4/site-packages
}
toPythonPath() {
local paths="$1"
local result=
for i in $paths; do
p="$i/lib/python3.4/site-packages"
result="${result}${result:+:}$p"
done
echo $result
}
envHooks+=(addPythonPath)

View File

@@ -13,6 +13,7 @@
, callPackage
, self
, CF, configd
, python-setup-hook
# For the Python package set
, pkgs, packageOverrides ? (self: super: {})
}:
@@ -102,7 +103,7 @@ in stdenv.mkDerivation {
''}
'';
setupHook = ./setup-hook.sh;
setupHook = python-setup-hook sitePackages;
postInstall = ''
# needed for some packages, especially packages that backport functionality

View File

@@ -1,15 +0,0 @@
addPythonPath() {
addToSearchPathWithCustomDelimiter : PYTHONPATH $1/lib/python3.5/site-packages
}
toPythonPath() {
local paths="$1"
local result=
for i in $paths; do
p="$i/lib/python3.5/site-packages"
result="${result}${result:+:}$p"
done
echo $result
}
envHooks+=(addPythonPath)

View File

@@ -14,6 +14,7 @@
, callPackage
, self
, CF, configd
, python-setup-hook
# For the Python package set
, pkgs, packageOverrides ? (self: super: {})
}:
@@ -94,7 +95,7 @@ in stdenv.mkDerivation {
''}
'';
setupHook = ./setup-hook.sh;
setupHook = python-setup-hook sitePackages;
postInstall = ''
# needed for some packages, especially packages that backport functionality

View File

@@ -1,15 +0,0 @@
addPythonPath() {
addToSearchPathWithCustomDelimiter : PYTHONPATH $1/lib/python3.6/site-packages
}
toPythonPath() {
local paths="$1"
local result=
for i in $paths; do
p="$i/lib/python3.6/site-packages"
result="${result}${result:+:}$p"
done
echo $result
}
envHooks+=(addPythonPath)