summaryrefslogtreecommitdiffstats
path: root/pkgs/development/interpreters/perl/wrapper.nix
blob: 06144c8cc5eab06af8658c9c3bae6f12b435d5d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{
  lib,
  perl,
  buildEnv,
  makeBinaryWrapper,
  stdenv,
  extraLibs ? [ ],
  extraOutputsToInstall ? [ ],
  postBuild ? "",
  ignoreCollisions ? false,
  requiredPerlModules,
}:

# Create a perl executable that knows about additional packages.
let
  env =
    let
      paths = requiredPerlModules (extraLibs ++ [ perl ]);
    in
    buildEnv {
      name = "${perl.name}-env";

      inherit paths;
      inherit ignoreCollisions;
      extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;

      # TODO: remove stdenv.cc as soon as it is added to propagatedNativeBuildInputs of makeBinaryWrapper
      nativeBuildInputs = [
        makeBinaryWrapper
        stdenv.cc
      ];

      # we create wrapper for the binaries in the different packages
      postBuild = ''
        if [ -L "$out/bin" ]; then
            unlink "$out/bin"
        fi
        mkdir -p "$out/bin"

        # 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
          fi
        done
      ''
      + postBuild;

      meta = perl.meta // {
        outputsToInstall = [ "out" ];
      }; # remove "man" from meta.outputsToInstall. pkgs.buildEnv produces no "man", it puts everything to "out"

      passthru = perl.passthru // {
        interpreter = "${env}/bin/perl";
        inherit perl;
      };
    };
in
env