From 0c9417100fb3172cfa874f0d8641471d91a94c76 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron <886074+teto@users.noreply.github.com> Date: Wed, 6 Mar 2024 22:41:35 +0100 Subject: [PATCH] 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. --- .../interpreters/lua-5/hooks/setup-hook.sh | 15 +++++++++------ 1 file 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 7b2d2a4d83d8..3041b7f1c3f7 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() {