2014-10-19 18:48:07 +01:00
|
|
|
{ stdenv, python, buildEnv, makeWrapper
|
|
|
|
, extraLibs ? []
|
2017-09-16 16:07:49 +01:00
|
|
|
, extraOutputsToInstall ? []
|
2014-10-19 18:48:07 +01:00
|
|
|
, postBuild ? ""
|
2014-10-12 13:59:31 +01:00
|
|
|
, ignoreCollisions ? false }:
|
2012-02-26 17:23:22 +00:00
|
|
|
|
2013-08-15 08:52:25 +01:00
|
|
|
# Create a python executable that knows about additional packages.
|
2014-10-19 18:48:07 +01:00
|
|
|
let
|
|
|
|
recursivePthLoader = import ../../python-modules/recursive-pth-loader/default.nix { stdenv = stdenv; python = python; };
|
2017-08-01 15:25:53 +01:00
|
|
|
env = let
|
2016-09-17 13:28:12 +01:00
|
|
|
paths = stdenv.lib.closePropagation (extraLibs ++ [ python recursivePthLoader ] ) ;
|
2015-11-19 12:16:15 +00:00
|
|
|
in buildEnv {
|
|
|
|
name = "${python.name}-env";
|
2014-02-24 11:41:12 +00:00
|
|
|
|
2015-11-19 12:16:15 +00:00
|
|
|
inherit paths;
|
2017-09-16 16:07:49 +01:00
|
|
|
inherit ignoreCollisions extraOutputsToInstall;
|
2010-08-16 18:03:35 +01:00
|
|
|
|
2015-08-14 12:06:15 +01:00
|
|
|
postBuild = ''
|
|
|
|
. "${makeWrapper}/nix-support/setup-hook"
|
2013-11-07 12:59:44 +00:00
|
|
|
|
2015-08-14 12:06:15 +01:00
|
|
|
if [ -L "$out/bin" ]; then
|
|
|
|
unlink "$out/bin"
|
|
|
|
fi
|
|
|
|
mkdir -p "$out/bin"
|
2013-11-07 12:59:44 +00:00
|
|
|
|
2015-11-19 12:16:15 +00:00
|
|
|
for path in ${stdenv.lib.concatStringsSep " " paths}; do
|
|
|
|
if [ -d "$path/bin" ]; then
|
|
|
|
cd "$path/bin"
|
|
|
|
for prg in *; do
|
|
|
|
if [ -f "$prg" ]; then
|
|
|
|
rm -f "$out/bin/$prg"
|
2017-08-09 14:06:03 +01:00
|
|
|
if [ -x "$prg" ]; then
|
|
|
|
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out" --set PYTHONNOUSERSITE "true"
|
|
|
|
fi
|
2015-11-19 12:16:15 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2015-08-14 12:06:15 +01:00
|
|
|
done
|
|
|
|
'' + postBuild;
|
|
|
|
|
2017-08-01 15:25:53 +01:00
|
|
|
inherit (python) meta;
|
|
|
|
|
|
|
|
passthru = python.passthru // {
|
|
|
|
interpreter = "${env}/bin/${python.executable}";
|
2017-08-02 14:05:00 +01:00
|
|
|
inherit python;
|
2017-08-01 15:25:53 +01:00
|
|
|
env = stdenv.mkDerivation {
|
|
|
|
name = "interactive-${python.name}-environment";
|
|
|
|
nativeBuildInputs = [ env ];
|
2015-08-14 12:06:15 +01:00
|
|
|
|
2017-08-01 15:25:53 +01:00
|
|
|
buildCommand = ''
|
|
|
|
echo >&2 ""
|
|
|
|
echo >&2 "*** Python 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
|
|
|
|
echo >&2 ""
|
|
|
|
exit 1
|
|
|
|
'';
|
|
|
|
};
|
2015-08-14 12:06:15 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in env
|