Merge pull request #9298 from abbradar/python-env
python: add .env for convenient nix-shell's
This commit is contained in:
commit
f044c31174
|
@ -464,6 +464,27 @@ python.buildEnv.override {
|
||||||
with wrapped binaries in <filename>bin/</filename>.
|
with wrapped binaries in <filename>bin/</filename>.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
You can also use <varname>env</varname> attribute to create local
|
||||||
|
environments with needed packages installed (somewhat comparable to
|
||||||
|
<literal>virtualenv</literal>). For example, with the following
|
||||||
|
<filename>shell.nix</filename>:
|
||||||
|
|
||||||
|
<programlisting language="nix">
|
||||||
|
<![CDATA[with import <nixpkgs> {};
|
||||||
|
|
||||||
|
(python3.buildEnv.override {
|
||||||
|
extraLibs = with python3Packages;
|
||||||
|
[ numpy
|
||||||
|
requests
|
||||||
|
];
|
||||||
|
}).env]]>
|
||||||
|
</programlisting>
|
||||||
|
|
||||||
|
Running <command>nix-shell</command> will drop you into a shell where
|
||||||
|
<command>python</command> will have specified packages in its path.
|
||||||
|
</para>
|
||||||
|
|
||||||
<variablelist>
|
<variablelist>
|
||||||
<title>
|
<title>
|
||||||
<function>python.buildEnv</function> arguments
|
<function>python.buildEnv</function> arguments
|
||||||
|
|
|
@ -6,28 +6,40 @@
|
||||||
# Create a python executable that knows about additional packages.
|
# Create a python executable that knows about additional packages.
|
||||||
let
|
let
|
||||||
recursivePthLoader = import ../../python-modules/recursive-pth-loader/default.nix { stdenv = stdenv; python = python; };
|
recursivePthLoader = import ../../python-modules/recursive-pth-loader/default.nix { stdenv = stdenv; python = python; };
|
||||||
in
|
env = (buildEnv {
|
||||||
(buildEnv {
|
name = "${python.name}-env";
|
||||||
name = "${python.name}-env";
|
paths = stdenv.lib.filter (x : x ? pythonPath) (stdenv.lib.closePropagation extraLibs) ++ [ python recursivePthLoader ];
|
||||||
paths = stdenv.lib.filter (x : x ? pythonPath) (stdenv.lib.closePropagation extraLibs) ++ [ python recursivePthLoader ];
|
|
||||||
|
|
||||||
inherit ignoreCollisions;
|
inherit ignoreCollisions;
|
||||||
|
|
||||||
postBuild = ''
|
postBuild = ''
|
||||||
. "${makeWrapper}/nix-support/setup-hook"
|
. "${makeWrapper}/nix-support/setup-hook"
|
||||||
|
|
||||||
if [ -L "$out/bin" ]; then
|
if [ -L "$out/bin" ]; then
|
||||||
unlink "$out/bin"
|
unlink "$out/bin"
|
||||||
fi
|
fi
|
||||||
mkdir -p "$out/bin"
|
mkdir -p "$out/bin"
|
||||||
|
|
||||||
cd "${python}/bin"
|
cd "${python}/bin"
|
||||||
for prg in *; do
|
for prg in *; do
|
||||||
rm -f "$out/bin/$prg"
|
rm -f "$out/bin/$prg"
|
||||||
makeWrapper "${python}/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out"
|
makeWrapper "${python}/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out"
|
||||||
done
|
done
|
||||||
'' + postBuild;
|
'' + postBuild;
|
||||||
}) // {
|
|
||||||
inherit python;
|
passthru.env = stdenv.mkDerivation {
|
||||||
inherit (python) meta;
|
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user