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