nixpkgs/pkgs/development/interpreters/lua-5/wrapper.nix
Alexei Robyn c62337d9c7 lua*Packages: Consolidate separate setup hooks together
- Lua packages now consistently use LUA_PATH/LUA_CPATH rather than a mix
  of those and NIX_LUA_PATH/NIX_LUA_CPATH
- Lua libraries are now consistently only added to the search path
variables if:
    1) The library actually has a corresponding directory to search
    2) The library is not already present in the search path
  This should help prevent the search paths from growing overly large
- Fixed bugs in some path helpers
- Changed the affected shell script indentation to 2 spaces; nixpkgs
  shell scripts are inconsistently split between 2 and 4 space
  indentation, but 2 matches better with the Nix expressions, so IMO it
  makes more sense
2019-09-01 17:42:20 +02:00

73 lines
2.0 KiB
Nix

{ stdenv, lua, buildEnv, makeWrapper
, extraLibs ? []
, extraOutputsToInstall ? []
, postBuild ? ""
, ignoreCollisions ? false
, requiredLuaModules
, makeWrapperArgs ? []
}:
# Create a lua executable that knows about additional packages.
let
env = let
paths = requiredLuaModules (extraLibs ++ [ lua ] );
in buildEnv {
name = "${lua.name}-env";
inherit paths;
inherit ignoreCollisions;
extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;
# we create wrapper for the binaries in the different packages
postBuild = ''
. "${makeWrapper}/nix-support/setup-hook"
# get access to lua functions
. ${lua}/nix-support/setup-hook
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
for path in ${stdenv.lib.concatStringsSep " " paths}; do
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"
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --suffix LUA_PATH ';' "$LUA_PATH" --suffix LUA_CPATH ';' "$LUA_CPATH" ${stdenv.lib.concatStringsSep " " makeWrapperArgs}
fi
fi
done
fi
done
'' + postBuild;
inherit (lua) meta;
passthru = lua.passthru // {
interpreter = "${env}/bin/lua";
inherit lua;
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
'';
};
};
};
in env