1{ stdenv, python, buildEnv, makeWrapper
2, extraLibs ? []
3, postBuild ? ""
4, ignoreCollisions ? false }:
5
6# Create a python executable that knows about additional packages.
7let
8 recursivePthLoader = import ../../python-modules/recursive-pth-loader/default.nix { stdenv = stdenv; python = python; };
9 env = (buildEnv {
10 name = "${python.name}-env";
11 paths = stdenv.lib.filter (x : x ? pythonPath) (stdenv.lib.closePropagation extraLibs) ++ [ python recursivePthLoader ];
12
13 inherit ignoreCollisions;
14
15 postBuild = ''
16 . "${makeWrapper}/nix-support/setup-hook"
17
18 if [ -L "$out/bin" ]; then
19 unlink "$out/bin"
20 fi
21 mkdir -p "$out/bin"
22
23 cd "${python}/bin"
24 for prg in *; do
25 rm -f "$out/bin/$prg"
26 makeWrapper "${python}/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out"
27 done
28 '' + postBuild;
29
30 passthru.env = stdenv.mkDerivation {
31 name = "interactive-${python.name}-environment";
32 nativeBuildInputs = [ env ];
33
34 buildCommand = ''
35 echo >&2 ""
36 echo >&2 "*** Python 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
37 echo >&2 ""
38 exit 1
39 '';
40 };
41 }) // {
42 inherit python;
43 inherit (python) meta;
44 };
45in env