1# set -e
2
3nix_print() {
4 if [ ${NIX_DEBUG:-0} -ge $1 ]; then
5 echo "$2"
6 fi
7}
8
9nix_debug() {
10 nix_print 3 "$1"
11}
12
13addToLuaSearchPathWithCustomDelimiter() {
14 local varName="$1"
15 local absPattern="$2"
16 # delete longest match starting from the lua placeholder '?'
17 local topDir="${absPattern%%\?*}"
18
19 # export only if the folder exists else LUA_PATH grows too big
20 if [ ! -d "$topDir" ]; then return; fi
21
22 export "${varName}=${!varName:+${!varName};}${absPattern}"
23}
24
25addToLuaPath() {
26 local dir="$1"
27
28 if [[ ! -d "$dir" ]]; then
29 nix_debug "$dir not a directory abort"
30 return 0
31 fi
32 cd "$dir"
33 for pattern in @luapathsearchpaths@;
34 do
35 addToLuaSearchPathWithCustomDelimiter NIX_LUA_PATH "$PWD/$pattern"
36 done
37
38 # LUA_CPATH
39 for pattern in @luacpathsearchpaths@;
40 do
41 addToLuaSearchPathWithCustomDelimiter NIX_LUA_CPATH "$PWD/$pattern"
42 done
43 cd - >/dev/null
44}
45
46addEnvHooks "$hostOffset" addToLuaPath
47