Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 24.05-beta 54 lines 1.3 kB view raw
1#!/bin/sh 2nix_print() { 3 if [ ${NIX_DEBUG:-0} -ge $1 ]; then 4 echo "$2" 5 fi 6} 7 8nix_debug() { 9 nix_print 3 "$1" 10} 11 12addToLuaSearchPathWithCustomDelimiter() { 13 local varName="$1" 14 local absPattern="$2" 15 16 # export only if we haven't already got this dir in the search path 17 if [[ ${!varName-} == *"$absPattern"* ]]; then return; fi 18 19 # if the path variable has not yet been set, initialize it to ";;" 20 # this is a magic value that will be replaced by the default, 21 # allowing relative modules to be used even when there are system modules. 22 if [[ ! -v "${varName}" ]]; then export "${varName}=;;"; fi 23 24 # export only if the folder contains lua files 25 shopt -s globstar 26 27 local adjustedPattern="${absPattern/\?/\*\*\/\*}" 28 for _file in $adjustedPattern; do 29 export "${varName}=${!varName:+${!varName};}${absPattern}" 30 shopt -u globstar 31 return; 32 done 33 shopt -u globstar 34} 35 36addToLuaPath() { 37 local dir="$1" 38 39 if [[ ! -d "$dir" ]]; then 40 nix_debug "$dir not a directory abort" 41 return 0 42 fi 43 cd "$dir" 44 for pattern in @luapathsearchpaths@; do 45 addToLuaSearchPathWithCustomDelimiter LUA_PATH "$PWD/$pattern" 46 done 47 48 # LUA_CPATH 49 for pattern in @luacpathsearchpaths@; do 50 addToLuaSearchPathWithCustomDelimiter LUA_CPATH "$PWD/$pattern" 51 done 52 cd - >/dev/null 53} 54