1 # Inspired by python/wrapper.nix
2 # Wrapper around wrapLuaProgramsIn, below. The $luaPath
3 # variable is passed in from the buildLuarocksPackage function.
7 wrapLuaProgramsIn
"$out/bin" "$out $luaPath"
10 # Builds environment variables like LUA_PATH and PATH walking through closure
16 # Create an empty table of paths (see doc on loadFromPropagatedInputs
17 # for how this is used). Build up the program_PATH and program_LUA_PATH
19 declare -A luaPathsSeen
=()
21 luaPathsSeen
["@lua@"]=1
22 addToSearchPath program_PATH @lua@
/bin
23 for path
in $luaPath; do
28 # with an executable shell script which will set some environment variables
29 # and then call into the original binary (which has been given a .wrapped suffix).
30 # luaPath is a list of directories
36 buildLuaPath
"$luaPath"
38 if [ ! -d "$dir" ]; then
39 nix_debug
"$dir not a directory"
43 nix_debug
"wrapping programs in [$dir]"
45 # Find all regular files in the output directory that are executable.
46 find "$dir" -type f
-perm -0100 -print0 |
while read -d "" f
; do
47 # Rewrite "#! .../env lua" to "#! /nix/store/.../lua".
48 # Strip suffix, like "3" or "2.7m" -- we don't have any choice on which
49 # Lua to use besides one with this hook anyway.
50 if head -n1 "$f" |
grep -q '#!.*/env.*\(lua\)'; then
51 sed -i "$f" -e "1 s^.*/env[ ]*\(lua\)[^ ]*^#! @executable@^"
54 # wrapProgram creates the executable shell script described
55 # above. The script will set LUA_(C)PATH and PATH variables!
56 # (see pkgs/build-support/setup-hooks/make-wrapper.sh)
57 local -a wrap_args
=("$f"
58 --prefix PATH
':' "$program_PATH"
59 --prefix LUA_PATH
';' "$LUA_PATH"
60 --prefix LUA_CPATH
';' "$LUA_CPATH"
63 # Add any additional arguments provided by makeWrapperArgs
64 # argument to buildLuaPackage.
66 local -a user_args
="($makeWrapperArgs)"
67 local -a wrapProgramArgs
=("${wrap_args[@]}" "${user_args[@]}")
69 # see setup-hooks/make-wrapper.sh
70 wrapProgram
"${wrapProgramArgs[@]}"
75 # Adds the lib and bin directories to the LUA_PATH and PATH variables,
76 # respectively. Recurses on any paths declared in
77 # `propagated-native-build-inputs`, while avoiding duplicating paths by
78 # flagging the directories it has visited in `luaPathsSeen`.
79 loadFromPropagatedInputs
() {
81 # Stop if we've already visited here.
82 if [ -n "${luaPathsSeen[$dir]}" ]; then
88 addToSearchPath program_PATH
$dir/bin
90 # Inspect the propagated inputs (if they exist) and recur on them.
91 local prop
="$dir/nix-support/propagated-native-build-inputs"
92 if [ -e "$prop" ]; then
94 for new_path
in $
(cat $prop); do
95 loadFromPropagatedInputs
"$new_path"