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