core/pkgs/by-name/pe/perl/wrapper.nix

64 lines
1.6 KiB
Nix
Raw Normal View History

2024-06-30 08:16:52 +00:00
{
lib,
perl,
buildEnv,
makeBinaryWrapper,
extraLibs ? [ ],
extraOutputsToInstall ? [ ],
postBuild ? "",
ignoreCollisions ? false,
requiredPerlModules,
2024-05-02 00:46:19 +00:00
}:
# Create a perl executable that knows about additional packages.
let
2024-06-30 08:16:52 +00:00
env =
let
paths = requiredPerlModules (extraLibs ++ [ perl ]);
in
buildEnv {
name = "${perl.name}-env";
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
inherit paths;
inherit ignoreCollisions;
extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
nativeBuildInputs = [ makeBinaryWrapper ];
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
# we create wrapper for the binaries in the different packages
postBuild =
''
if [ -L "$out/bin" ]; then
unlink "$out/bin"
fi
mkdir -p "$out/bin"
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
# take every binary from perl packages and put them into the env
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" --suffix PERL5LIB ':' "$out/${perl.libPrefix}"
fi
fi
done
2024-05-02 00:46:19 +00:00
fi
done
2024-06-30 08:16:52 +00:00
''
+ postBuild;
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
meta = perl.meta // {
outputsToInstall = [ "out" ];
}; # remove "man" from meta.outputsToInstall. pkgs.buildEnv produces no "man", it puts everything to "out"
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
passthru = perl.passthru // {
interpreter = "${env}/bin/perl";
inherit perl;
};
2024-05-02 00:46:19 +00:00
};
2024-06-30 08:16:52 +00:00
in
env