1{ stdenv, python, buildEnv, makeWrapper
2, extraLibs ? []
3, extraOutputsToInstall ? []
4, postBuild ? ""
5, ignoreCollisions ? false
6, requiredPythonModules
7, }:
8
9# Create a python executable that knows about additional packages.
10let
11 env = let
12 paths = requiredPythonModules (extraLibs ++ [ python ] ) ;
13 in buildEnv {
14 name = "${python.name}-env";
15
16 inherit paths;
17 inherit ignoreCollisions;
18 extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;
19
20 postBuild = ''
21 . "${makeWrapper}/nix-support/setup-hook"
22
23 if [ -L "$out/bin" ]; then
24 unlink "$out/bin"
25 fi
26 mkdir -p "$out/bin"
27
28 for path in ${stdenv.lib.concatStringsSep " " paths}; do
29 if [ -d "$path/bin" ]; then
30 cd "$path/bin"
31 for prg in *; do
32 if [ -f "$prg" ]; then
33 rm -f "$out/bin/$prg"
34 if [ -x "$prg" ]; then
35 makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out" --set PYTHONNOUSERSITE "true"
36 fi
37 fi
38 done
39 fi
40 done
41 '' + postBuild;
42
43 inherit (python) meta;
44
45 passthru = python.passthru // {
46 interpreter = "${env}/bin/${python.executable}";
47 inherit python;
48 env = stdenv.mkDerivation {
49 name = "interactive-${python.name}-environment";
50 nativeBuildInputs = [ env ];
51
52 buildCommand = ''
53 echo >&2 ""
54 echo >&2 "*** Python 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
55 echo >&2 ""
56 exit 1
57 '';
58 };
59 };
60 };
61in env