2014-10-19 10:48:07 -07:00
|
|
|
{ stdenv, python, buildEnv, makeWrapper
|
|
|
|
, extraLibs ? []
|
2017-09-16 08:07:49 -07:00
|
|
|
, extraOutputsToInstall ? []
|
2014-10-19 10:48:07 -07:00
|
|
|
, postBuild ? ""
|
2017-05-28 00:20:47 -07:00
|
|
|
, ignoreCollisions ? false
|
|
|
|
, requiredPythonModules
|
2018-10-13 01:56:51 -07:00
|
|
|
# Wrap executables with the given argument.
|
|
|
|
, makeWrapperArgs ? []
|
2017-05-28 00:20:47 -07:00
|
|
|
, }:
|
2012-02-26 09:23:22 -08:00
|
|
|
|
2013-08-15 00:52:25 -07:00
|
|
|
# Create a python executable that knows about additional packages.
|
2014-10-19 10:48:07 -07:00
|
|
|
let
|
2017-08-01 07:25:53 -07:00
|
|
|
env = let
|
2017-05-28 00:20:47 -07:00
|
|
|
paths = requiredPythonModules (extraLibs ++ [ python ] ) ;
|
2015-11-19 04:16:15 -08:00
|
|
|
in buildEnv {
|
|
|
|
name = "${python.name}-env";
|
2014-02-24 03:41:12 -08:00
|
|
|
|
2015-11-19 04:16:15 -08:00
|
|
|
inherit paths;
|
2017-12-10 06:21:02 -08:00
|
|
|
inherit ignoreCollisions;
|
|
|
|
extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;
|
2010-08-16 10:03:35 -07:00
|
|
|
|
2015-08-14 04:06:15 -07:00
|
|
|
postBuild = ''
|
|
|
|
. "${makeWrapper}/nix-support/setup-hook"
|
2013-11-07 04:59:44 -08:00
|
|
|
|
2015-08-14 04:06:15 -07:00
|
|
|
if [ -L "$out/bin" ]; then
|
|
|
|
unlink "$out/bin"
|
|
|
|
fi
|
|
|
|
mkdir -p "$out/bin"
|
2013-11-07 04:59:44 -08:00
|
|
|
|
2015-11-19 04:16:15 -08: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 06:06:03 -07:00
|
|
|
if [ -x "$prg" ]; then
|
2018-10-13 01:56:51 -07:00
|
|
|
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out" --set PYTHONNOUSERSITE "true" ${stdenv.lib.concatStringsSep " " makeWrapperArgs}
|
2017-08-09 06:06:03 -07:00
|
|
|
fi
|
2015-11-19 04:16:15 -08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2015-08-14 04:06:15 -07:00
|
|
|
done
|
|
|
|
'' + postBuild;
|
|
|
|
|
2017-08-01 07:25:53 -07:00
|
|
|
inherit (python) meta;
|
|
|
|
|
|
|
|
passthru = python.passthru // {
|
|
|
|
interpreter = "${env}/bin/${python.executable}";
|
2017-08-02 06:05:00 -07:00
|
|
|
inherit python;
|
2017-08-01 07:25:53 -07:00
|
|
|
env = stdenv.mkDerivation {
|
|
|
|
name = "interactive-${python.name}-environment";
|
|
|
|
nativeBuildInputs = [ env ];
|
2015-08-14 04:06:15 -07:00
|
|
|
|
2017-08-01 07:25:53 -07: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 04:06:15 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in env
|