2021-02-05 17:12:51 +00:00
|
|
|
{ lib, stdenv, lua, buildEnv, makeWrapper
|
2020-04-24 23:36:52 +00:00
|
|
|
, extraLibs ? []
|
|
|
|
, extraOutputsToInstall ? []
|
|
|
|
, postBuild ? ""
|
|
|
|
, ignoreCollisions ? false
|
|
|
|
, requiredLuaModules
|
|
|
|
, makeWrapperArgs ? []
|
|
|
|
}:
|
|
|
|
|
|
|
|
# Create a lua executable that knows about additional packages.
|
|
|
|
let
|
|
|
|
env = let
|
|
|
|
paths = requiredLuaModules (extraLibs ++ [ lua ] );
|
2021-09-18 10:52:07 +00:00
|
|
|
in buildEnv {
|
2020-04-24 23:36:52 +00:00
|
|
|
name = "${lua.name}-env";
|
|
|
|
|
|
|
|
inherit paths;
|
|
|
|
inherit ignoreCollisions;
|
|
|
|
extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
makeWrapper
|
|
|
|
(lua.pkgs.lua-setup-hook lua.LuaPathSearchPaths lua.LuaCPathSearchPaths)
|
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# we create wrapper for the binaries in the different packages
|
|
|
|
postBuild = ''
|
|
|
|
if [ -L "$out/bin" ]; then
|
|
|
|
unlink "$out/bin"
|
|
|
|
fi
|
|
|
|
mkdir -p "$out/bin"
|
|
|
|
|
|
|
|
addToLuaPath "$out"
|
|
|
|
|
|
|
|
# take every binary from lua packages and put them into the env
|
2021-02-05 17:12:51 +00:00
|
|
|
for path in ${lib.concatStringsSep " " paths}; do
|
2020-04-24 23:36:52 +00:00
|
|
|
nix_debug "looking for binaries in path = $path"
|
|
|
|
if [ -d "$path/bin" ]; then
|
|
|
|
cd "$path/bin"
|
|
|
|
for prg in *; do
|
|
|
|
if [ -f "$prg" ]; then
|
|
|
|
rm -f "$out/bin/$prg"
|
|
|
|
if [ -x "$prg" ]; then
|
|
|
|
nix_debug "Making wrapper $prg"
|
2021-09-18 10:52:07 +00:00
|
|
|
makeWrapper "$path/bin/$prg" "$out/bin/$prg" \
|
|
|
|
--set-default LUA_PATH ";;" \
|
|
|
|
--suffix LUA_PATH ';' "$LUA_PATH" \
|
|
|
|
--set-default LUA_CPATH ";;" \
|
|
|
|
--suffix LUA_CPATH ';' "$LUA_CPATH" \
|
|
|
|
${lib.concatStringsSep " " makeWrapperArgs}
|
2020-04-24 23:36:52 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
'' + postBuild;
|
|
|
|
|
|
|
|
inherit (lua) meta;
|
|
|
|
|
|
|
|
passthru = lua.passthru // {
|
|
|
|
interpreter = "${env}/bin/lua";
|
|
|
|
inherit lua;
|
2022-10-21 18:38:19 +00:00
|
|
|
luaPath = lua.pkgs.lib.genLuaPathAbsStr env;
|
|
|
|
luaCpath = lua.pkgs.lib.genLuaCPathAbsStr env;
|
2020-04-24 23:36:52 +00:00
|
|
|
env = stdenv.mkDerivation {
|
|
|
|
name = "interactive-${lua.name}-environment";
|
|
|
|
nativeBuildInputs = [ env ];
|
|
|
|
|
|
|
|
buildCommand = ''
|
|
|
|
echo >&2 ""
|
|
|
|
echo >&2 "*** lua 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
|
|
|
|
echo >&2 ""
|
|
|
|
exit 1
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2021-09-18 10:52:07 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
in env
|