2022-04-19 11:01:06 +00:00
|
|
|
{ lib, stdenv, buildEnv, makeBinaryWrapper
|
2021-03-02 22:33:53 +00:00
|
|
|
|
|
|
|
# manually pased
|
|
|
|
, python
|
|
|
|
, requiredPythonModules
|
|
|
|
|
|
|
|
# extra opts
|
2014-10-19 17:48:07 +00:00
|
|
|
, extraLibs ? []
|
2017-09-16 15:07:49 +00:00
|
|
|
, extraOutputsToInstall ? []
|
2014-10-19 17:48:07 +00:00
|
|
|
, postBuild ? ""
|
2017-05-28 07:20:47 +00:00
|
|
|
, ignoreCollisions ? false
|
2018-12-06 23:18:59 +00:00
|
|
|
, permitUserSite ? false
|
2018-10-13 08:56:51 +00:00
|
|
|
# Wrap executables with the given argument.
|
|
|
|
, makeWrapperArgs ? []
|
2017-05-28 07:20:47 +00:00
|
|
|
, }:
|
2012-02-26 17:23:22 +00:00
|
|
|
|
2013-08-15 07:52:25 +00:00
|
|
|
# Create a python executable that knows about additional packages.
|
2014-10-19 17:48:07 +00:00
|
|
|
let
|
2017-08-01 14:25:53 +00:00
|
|
|
env = let
|
2017-05-28 07:20:47 +00:00
|
|
|
paths = requiredPythonModules (extraLibs ++ [ python ] ) ;
|
2019-07-09 12:34:15 +00:00
|
|
|
pythonPath = "${placeholder "out"}/${python.sitePackages}";
|
2019-07-27 07:30:34 +00:00
|
|
|
pythonExecutable = "${placeholder "out"}/bin/${python.executable}";
|
2015-11-19 12:16:15 +00:00
|
|
|
in buildEnv {
|
|
|
|
name = "${python.name}-env";
|
2014-02-24 11:41:12 +00:00
|
|
|
|
2015-11-19 12:16:15 +00:00
|
|
|
inherit paths;
|
2017-12-10 14:21:02 +00:00
|
|
|
inherit ignoreCollisions;
|
|
|
|
extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;
|
2010-08-16 17:03:35 +00:00
|
|
|
|
2022-04-19 11:01:06 +00:00
|
|
|
nativeBuildInputs = [ makeBinaryWrapper ];
|
2013-11-07 12:59:44 +00:00
|
|
|
|
2021-03-02 22:33:53 +00:00
|
|
|
postBuild = ''
|
2015-08-14 11:06:15 +00:00
|
|
|
if [ -L "$out/bin" ]; then
|
|
|
|
unlink "$out/bin"
|
|
|
|
fi
|
|
|
|
mkdir -p "$out/bin"
|
2013-11-07 12:59:44 +00:00
|
|
|
|
2021-01-23 13:15:07 +00:00
|
|
|
for path in ${lib.concatStringsSep " " paths}; do
|
2015-11-19 12:16:15 +00:00
|
|
|
if [ -d "$path/bin" ]; then
|
|
|
|
cd "$path/bin"
|
|
|
|
for prg in *; do
|
|
|
|
if [ -f "$prg" ]; then
|
|
|
|
rm -f "$out/bin/$prg"
|
2017-08-09 13:06:03 +00:00
|
|
|
if [ -x "$prg" ]; then
|
2021-01-23 13:15:07 +00:00
|
|
|
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set NIX_PYTHONPREFIX "$out" --set NIX_PYTHONEXECUTABLE ${pythonExecutable} --set NIX_PYTHONPATH ${pythonPath} ${if permitUserSite then "" else ''--set PYTHONNOUSERSITE "true"''} ${lib.concatStringsSep " " makeWrapperArgs}
|
2017-08-09 13:06:03 +00:00
|
|
|
fi
|
2015-11-19 12:16:15 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2015-08-14 11:06:15 +00:00
|
|
|
done
|
|
|
|
'' + postBuild;
|
|
|
|
|
2017-08-01 14:25:53 +00:00
|
|
|
inherit (python) meta;
|
|
|
|
|
|
|
|
passthru = python.passthru // {
|
|
|
|
interpreter = "${env}/bin/${python.executable}";
|
2017-08-02 13:05:00 +00:00
|
|
|
inherit python;
|
2017-08-01 14:25:53 +00:00
|
|
|
env = stdenv.mkDerivation {
|
|
|
|
name = "interactive-${python.name}-environment";
|
|
|
|
nativeBuildInputs = [ env ];
|
2015-08-14 11:06:15 +00:00
|
|
|
|
2017-08-01 14:25:53 +00: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 11:06:15 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in env
|