374e6bcc40
Format all Nix files using the officially approved formatter, making the CI check introduced in the previous commit succeed: nix-build ci -A fmt.check This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153) of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166). This commit will lead to merge conflicts for a number of PRs, up to an estimated ~1100 (~33%) among the PRs with activity in the past 2 months, but that should be lower than what it would be without the previous [partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537). Merge conflicts caused by this commit can now automatically be resolved while rebasing using the [auto-rebase script](https://github.com/NixOS/nixpkgs/tree/8616af08d915377bd930395f3b700a0e93d08728/maintainers/scripts/auto-rebase). If you run into any problems regarding any of this, please reach out to the [formatting team](https://nixos.org/community/teams/formatting/) by pinging @NixOS/nix-formatting.
83 lines
2.2 KiB
Nix
83 lines
2.2 KiB
Nix
{
|
|
lib,
|
|
stdenv,
|
|
buildEnv,
|
|
makeBinaryWrapper,
|
|
|
|
# manually pased
|
|
python,
|
|
requiredPythonModules,
|
|
|
|
# extra opts
|
|
extraLibs ? [ ],
|
|
extraOutputsToInstall ? [ ],
|
|
postBuild ? "",
|
|
ignoreCollisions ? false,
|
|
permitUserSite ? false,
|
|
# Wrap executables with the given argument.
|
|
makeWrapperArgs ? [ ],
|
|
}:
|
|
|
|
# Create a python executable that knows about additional packages.
|
|
let
|
|
env =
|
|
let
|
|
paths = requiredPythonModules (extraLibs ++ [ python ]);
|
|
pythonPath = "${placeholder "out"}/${python.sitePackages}";
|
|
pythonExecutable = "${placeholder "out"}/bin/${python.executable}";
|
|
in
|
|
buildEnv {
|
|
name = "${python.name}-env";
|
|
|
|
inherit paths;
|
|
inherit ignoreCollisions;
|
|
extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;
|
|
|
|
nativeBuildInputs = [ makeBinaryWrapper ];
|
|
|
|
postBuild =
|
|
''
|
|
if [ -L "$out/bin" ]; then
|
|
unlink "$out/bin"
|
|
fi
|
|
mkdir -p "$out/bin"
|
|
|
|
for path in ${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"
|
|
if [ -x "$prg" ]; then
|
|
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set NIX_PYTHONPREFIX "$out" --set NIX_PYTHONEXECUTABLE ${pythonExecutable} --set NIX_PYTHONPATH ${pythonPath} ${
|
|
lib.optionalString (!permitUserSite) ''--set PYTHONNOUSERSITE "true"''
|
|
} ${lib.concatStringsSep " " makeWrapperArgs}
|
|
fi
|
|
fi
|
|
done
|
|
fi
|
|
done
|
|
''
|
|
+ postBuild;
|
|
|
|
inherit (python) meta;
|
|
|
|
passthru = python.passthru // {
|
|
interpreter = "${env}/bin/${python.executable}";
|
|
inherit python;
|
|
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
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
in
|
|
env
|