about summary refs log tree commit diff
path: root/pkgs/development/interpreters/lua-5
diff options
context:
space:
mode:
authorMatthieu Coudron <886074+teto@users.noreply.github.com>2024-03-06 22:41:35 +0100
committerMatthieu Coudron <886074+teto@users.noreply.github.com>2024-03-16 14:37:10 +0100
commit0c9417100fb3172cfa874f0d8641471d91a94c76 (patch)
treeffa1a70e08aac861580537679d900996365cc43d /pkgs/development/interpreters/lua-5
parent815d3683f70470e4c1b6c72535576e5e41d731ae (diff)
lua: update setup-hook to limit LUA_PATH size
now that the lua interpreters include working directories with `./?.lua`
in LUA_PATH, the current test includes every derivation which quickly
becomes unreadable and unpractical.
The test is adapted to add a folder only if it can find lua files in the
subfolder.
Diffstat (limited to 'pkgs/development/interpreters/lua-5')
-rw-r--r--pkgs/development/interpreters/lua-5/hooks/setup-hook.sh15
1 files changed, 9 insertions, 6 deletions
diff --git a/pkgs/development/interpreters/lua-5/hooks/setup-hook.sh b/pkgs/development/interpreters/lua-5/hooks/setup-hook.sh
index 7b2d2a4d83d86..3041b7f1c3f71 100644
--- a/pkgs/development/interpreters/lua-5/hooks/setup-hook.sh
+++ b/pkgs/development/interpreters/lua-5/hooks/setup-hook.sh
@@ -13,11 +13,6 @@ nix_debug() {
 addToLuaSearchPathWithCustomDelimiter() {
   local varName="$1"
   local absPattern="$2"
-  # delete longest match starting from the lua placeholder '?'
-  local topDir="${absPattern%%\?*}"
-
-  # export only if the folder exists else LUA_PATH/LUA_CPATH grow too large
-  if [[ ! -d "$topDir" ]]; then return; fi
 
   # export only if we haven't already got this dir in the search path
   if [[ ${!varName-} == *"$absPattern"* ]]; then return; fi
@@ -27,7 +22,15 @@ addToLuaSearchPathWithCustomDelimiter() {
   # allowing relative modules to be used even when there are system modules.
   if [[ ! -v "${varName}" ]]; then export "${varName}=;;"; fi
 
-  export "${varName}=${!varName:+${!varName};}${absPattern}"
+  # export only if the folder contains lua files
+  shopt -s globstar
+
+  for _file in ${absPattern/\?/\*\*}; do
+    export "${varName}=${!varName:+${!varName};}${absPattern}"
+    shopt -u globstar
+    return;
+  done
+  shopt -u globstar
 }
 
 addToLuaPath() {