lua: take into propagated-build-inputs when building LUA_PATH

so far we ignored propagated-build-inputs

Changed files
+98 -48
pkgs
development
+1 -1
pkgs/development/interpreters/lua-5/interpreter.nix
···
LuaCPathSearchPaths = luaPackages.luaLib.luaCPathList;
setupHook = builtins.toFile "lua-setup-hook" ''
source @out@/nix-support/utils.sh
-
addEnvHooks "$hostOffset" addToLuaPath
+
addEnvHooks "$hostOffset" luaEnvHook
'';
nativeBuildInputs = [ makeWrapper ];
+13
pkgs/development/interpreters/lua-5/tests/default.nix
···
touch $out
'');
+
+
+
/*
+
Check that a lua package's propagatedBuildInputs end up in LUA_PATH
+
*/
+
checkPropagatedBuildInputs = pkgs.runCommandLocal "test-${lua.name}-setup-hook" ({
+
# lua-curl is a propagatedBuildInput of rest-nvim has
+
buildInputs = [ lua.pkgs.rest-nvim ];
+
}) (''
+
${lua}/bin/lua -e "require'cURL'"
+
touch $out
+
'');
+
})
+82 -1
pkgs/development/interpreters/lua-5/utils.sh
···
-
#!/bin/sh
+
#!/bin/bash
+
+
declare -gA luaPathsSeen=()
+
+
# shellcheck disable=SC2164,SC2041
nix_print() {
if [ ${NIX_DEBUG:-0} -ge $1 ]; then
echo "$2"
···
shopt -u globstar
}
+
# used in setup Hooks to load LUA_PATH and LUA_CPATH
+
# luaEnvHook
+
luaEnvHook() {
+
_addToLuaPath "$1"
+
}
+
addToLuaPath() {
local dir="$1"
+
if [ ! -d "$dir" ]; then
+
nix_debug "$dir not a directory abort"
+
return 0
+
fi
+
cd "$dir"
+
for pattern in @luapathsearchpaths@; do
+
addToLuaSearchPathWithCustomDelimiter LUA_PATH "$PWD/$pattern"
+
done
+
+
# LUA_CPATH
+
for pattern in @luacpathsearchpaths@; do
+
addToLuaSearchPathWithCustomDelimiter LUA_CPATH "$PWD/$pattern"
+
done
+
cd - >/dev/null
+
}
+
+
+
_addToLuaPath() {
+
local dir="$1"
+
+
echo "_addToLuaPath called for dir $dir"
+
if [[ ! -d "$dir" ]]; then
nix_debug "$dir not a directory abort"
return 0
fi
+
+
# set -x
+
# if [ -n "${pythonPathsSeen[$dir]}" ]; then return; fi
+
if [[ -n "${luaPathsSeen[$dir]:-}" ]]; then
+
# if [ -n "${luaPathsSeen[$dir]}" ]; then
+
echo "$dir already parsed"
+
return
+
fi
+
+
luaPathsSeen["$dir"]=true
+
+
# shellcheck disable=SC2164
cd "$dir"
for pattern in @luapathsearchpaths@; do
addToLuaSearchPathWithCustomDelimiter LUA_PATH "$PWD/$pattern"
···
for pattern in @luacpathsearchpaths@; do
addToLuaSearchPathWithCustomDelimiter LUA_CPATH "$PWD/$pattern"
done
+
cd - >/dev/null
+
+
addToSearchPath program_PATH "$dir"/bin
+
+
# Inspect the propagated inputs (if they exist) and recur on them.
+
local prop="$dir/nix-support/propagated-build-inputs"
+
if [ -e "$prop" ]; then
+
local new_path
+
for new_path in $(cat $prop); do
+
echo "newpath: $new_path"
+
_addToLuaPath "$new_path"
+
done
+
fi
+
}
+
# Builds environment variables like LUA_PATH and PATH walking through closure
+
# of dependencies.
+
buildLuaPath() {
+
local luaPath="$1"
+
local path
+
+
echo "BUILD_LUA_PATH"
+
+
# # set -x
+
# # Create an empty table of paths (see doc on loadFromPropagatedInputs
+
# # for how this is used). Build up the program_PATH and program_LUA_PATH
+
# # variables.
+
# declare -gA luaPathsSeen=()
+
# # shellcheck disable=SC2034
+
program_PATH=
+
luaPathsSeen["@lua@"]=1
+
# addToSearchPath program_PATH @lua@/bin
+
for path in $luaPath; do
+
_addToLuaPath "$path"
+
done
+
}
+
+
-44
pkgs/development/interpreters/lua-5/wrap.sh
···
wrapLuaProgramsIn "$out/bin" "$out $luaPath"
}
-
# Builds environment variables like LUA_PATH and PATH walking through closure
-
# of dependencies.
-
buildLuaPath() {
-
local luaPath="$1"
-
local path
-
-
# Create an empty table of paths (see doc on loadFromPropagatedInputs
-
# for how this is used). Build up the program_PATH and program_LUA_PATH
-
# variables.
-
declare -A luaPathsSeen=()
-
program_PATH=
-
luaPathsSeen["@lua@"]=1
-
addToSearchPath program_PATH @lua@/bin
-
for path in $luaPath; do
-
addToLuaPath "$path"
-
done
-
}
-
# with an executable shell script which will set some environment variables
# and then call into the original binary (which has been given a .wrapped suffix).
# luaPath is a list of directories
···
# Find all regular files in the output directory that are executable.
find "$dir" -type f -perm -0100 -print0 | while read -d "" f; do
# Rewrite "#! .../env lua" to "#! /nix/store/.../lua".
-
# Strip suffix, like "3" or "2.7m" -- we don't have any choice on which
# Lua to use besides one with this hook anyway.
if head -n1 "$f" | grep -q '#!.*/env.*\(lua\)'; then
sed -i "$f" -e "1 s^.*/env[ ]*\(lua\)[^ ]*^#! @executable@^"
···
done
}
-
-
# Adds the lib and bin directories to the LUA_PATH and PATH variables,
-
# respectively. Recurses on any paths declared in
-
# `propagated-native-build-inputs`, while avoiding duplicating paths by
-
# flagging the directories it has visited in `luaPathsSeen`.
-
loadFromPropagatedInputs() {
-
local dir="$1"
-
# Stop if we've already visited here.
-
if [ -n "${luaPathsSeen[$dir]}" ]; then
-
return
-
fi
-
luaPathsSeen[$dir]=1
-
-
addToLuaPath "$dir"
-
addToSearchPath program_PATH $dir/bin
-
-
# Inspect the propagated inputs (if they exist) and recur on them.
-
local prop="$dir/nix-support/propagated-native-build-inputs"
-
if [ -e "$prop" ]; then
-
local new_path
-
for new_path in $(cat $prop); do
-
loadFromPropagatedInputs "$new_path"
-
done
-
fi
-
}
+1 -1
pkgs/development/interpreters/lua-5/wrapper.nix
···
fi
mkdir -p "$out/bin"
-
addToLuaPath "$out"
+
buildLuaPath "$out"
# take every binary from lua packages and put them into the env
for path in ${lib.concatStringsSep " " paths}; do
+1 -1
pkgs/development/interpreters/luajit/default.nix
···
setupHook = builtins.toFile "lua-setup-hook" ''
source @out@/nix-support/utils.sh
-
addEnvHooks "$hostOffset" addToLuaPath
+
addEnvHooks "$hostOffset" luaEnvHook
'';
# copied from python