forked from mirrors/nixpkgs
1dbb72b91a
python.buildenv is used to build an env that provides binaries that can import all modules that were passed in to the env. Before this change it filtered the propagatedBuildInputs to remove all non-Python packages, thereby possibly reducing the amount of packages that were referenced. However, Python packages often don't have non- Python packages as propagatedBuildInputs. And occasionally, we do want to be able to add other packages to the env.
55 lines
1.4 KiB
Nix
55 lines
1.4 KiB
Nix
{ stdenv, python, buildEnv, makeWrapper
|
|
, extraLibs ? []
|
|
, postBuild ? ""
|
|
, ignoreCollisions ? false }:
|
|
|
|
# Create a python executable that knows about additional packages.
|
|
let
|
|
recursivePthLoader = import ../../python-modules/recursive-pth-loader/default.nix { stdenv = stdenv; python = python; };
|
|
env = (
|
|
let
|
|
paths = stdenv.lib.closePropagation (extraLibs ++ [ python recursivePthLoader ] ) ;
|
|
in buildEnv {
|
|
name = "${python.name}-env";
|
|
|
|
inherit paths;
|
|
inherit ignoreCollisions;
|
|
|
|
postBuild = ''
|
|
. "${makeWrapper}/nix-support/setup-hook"
|
|
|
|
if [ -L "$out/bin" ]; then
|
|
unlink "$out/bin"
|
|
fi
|
|
mkdir -p "$out/bin"
|
|
|
|
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"
|
|
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out"
|
|
fi
|
|
done
|
|
fi
|
|
done
|
|
'' + postBuild;
|
|
|
|
passthru.env = stdenv.mkDerivation {
|
|
name = "interactive-${python.name}-environment";
|
|
nativeBuildInputs = [ env ];
|
|
|
|
buildCommand = ''
|
|
echo >&2 ""
|
|
echo >&2 "*** Python 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
|
|
echo >&2 ""
|
|
exit 1
|
|
'';
|
|
};
|
|
}) // {
|
|
inherit python;
|
|
inherit (python) meta;
|
|
};
|
|
in env
|