1{
2 lib,
3 stdenv,
4 lua,
5 buildEnv,
6 makeWrapper,
7 extraLibs ? [ ],
8 extraOutputsToInstall ? [ ],
9 postBuild ? "",
10 ignoreCollisions ? false,
11 requiredLuaModules,
12 makeWrapperArgs ? [ ],
13}:
14
15# Create a lua executable that knows about additional packages.
16let
17 env =
18 let
19 paths = [ lua ] ++ requiredLuaModules extraLibs;
20 in
21 buildEnv {
22 name = "${lua.name}-env";
23
24 inherit paths;
25 inherit ignoreCollisions;
26 extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;
27
28 nativeBuildInputs = [
29 makeWrapper
30 ];
31
32 # we create wrapper for the binaries in the different packages
33 postBuild = ''
34 source ${lua}/nix-support/utils.sh
35 if [ -L "$out/bin" ]; then
36 unlink "$out/bin"
37 fi
38 mkdir -p "$out/bin"
39
40 buildLuaPath "$out"
41
42 # take every binary from lua packages and put them into the env
43 for path in ${lib.concatStringsSep " " paths}; do
44 nix_debug "looking for binaries in path = $path"
45 if [ -d "$path/bin" ]; then
46 cd "$path/bin"
47 for prg in *; do
48 if [ -f "$prg" ]; then
49 rm -f "$out/bin/$prg"
50 if [ -x "$prg" ]; then
51 nix_debug "Making wrapper $prg"
52 makeWrapper "$path/bin/$prg" "$out/bin/$prg" \
53 --set-default LUA_PATH ";;" \
54 --suffix LUA_PATH ';' "$LUA_PATH" \
55 --set-default LUA_CPATH ";;" \
56 --suffix LUA_CPATH ';' "$LUA_CPATH" \
57 ${lib.concatStringsSep " " makeWrapperArgs}
58 fi
59 fi
60 done
61 fi
62 done
63 ''
64 + postBuild;
65
66 inherit (lua) meta;
67
68 passthru = lua.passthru // {
69 interpreter = "${env}/bin/lua";
70 inherit lua;
71 luaPath = lua.pkgs.luaLib.genLuaPathAbsStr env;
72 luaCpath = lua.pkgs.luaLib.genLuaCPathAbsStr env;
73 env = stdenv.mkDerivation {
74 name = "interactive-${lua.name}-environment";
75 nativeBuildInputs = [ env ];
76
77 buildCommand = ''
78 echo >&2 ""
79 echo >&2 "*** lua 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
80 echo >&2 ""
81 exit 1
82 '';
83 };
84 };
85 };
86in
87env