at master 1.7 kB view raw
1# Inspired by python/wrapper.nix 2# Wrapper around wrapLuaProgramsIn, below. The $luaPath 3# variable is passed in from the buildLuarocksPackage function. 4set -e 5 6source @lua@/nix-support/utils.sh 7 8wrapLuaPrograms() { 9 wrapLuaProgramsIn "$out/bin" "$out $luaPath" 10} 11 12# with an executable shell script which will set some environment variables 13# and then call into the original binary (which has been given a .wrapped suffix). 14# luaPath is a list of directories 15wrapLuaProgramsIn() { 16 local dir="$1" 17 local luaPath="$2" 18 local f 19 20 buildLuaPath "$luaPath" 21 22 if [ ! -d "$dir" ]; then 23 nix_debug "$dir not a directory" 24 return 25 fi 26 27 nix_debug "wrapping programs in [$dir]" 28 29 # Find all regular files in the output directory that are executable. 30 find "$dir" -type f -perm -0100 -print0 | while read -d "" f; do 31 # Rewrite "#! .../env lua" to "#! /nix/store/.../lua". 32 # Lua to use besides one with this hook anyway. 33 if head -n1 "$f" | grep -q '#!.*/env.*\(lua\)'; then 34 sed -i "$f" -e "1 s^.*/env[ ]*\(lua\)[^ ]*^#! @executable@^" 35 fi 36 37 # wrapProgram creates the executable shell script described 38 # above. The script will set LUA_(C)PATH and PATH variables! 39 # (see pkgs/build-support/setup-hooks/make-wrapper.sh) 40 local -a wrap_args=("$f" 41 --prefix PATH ':' "$program_PATH" 42 --prefix LUA_PATH ';' "$LUA_PATH" 43 --prefix LUA_CPATH ';' "$LUA_CPATH" 44 ) 45 46 # Add any additional arguments provided by makeWrapperArgs 47 # argument to buildLuaPackage. 48 # makeWrapperArgs 49 local -a user_args="($makeWrapperArgs)" 50 local -a wrapProgramArgs=("${wrap_args[@]}" "${user_args[@]}") 51 52 # see setup-hooks/make-wrapper.sh 53 wrapProgram "${wrapProgramArgs[@]}" 54 55 done 56}