3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/development/interpreters/lua-5/wrapper.nix
John Ericson a610a38cb5 lua wrapper: Fix bash error
Recently, we made it harder for external code to use some stdenv-only bash
variables by unsetting them in [1] But Lua's `withPackages` was sourcing some
setup hooks in [2], which required those bash variables.

I say great! We caught something bad: Lua should use normal dependencies, even
though that is harder with `buildEnv`. Now it works that way, and everything is
fine.

[1]: 9d3911f806/pkgs/stdenv/generic/setup.sh (L574-L578)

[2]: 9d3911f806/pkgs/development/interpreters/lua-5/wrapper.nix (L23-L27)

CC @matthewbauer
2019-11-22 19:47:27 -05:00

70 lines
1.9 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 = ''
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
'';
};
};
}).overrideAttrs (_: {
# Add extra deps needed for postBuild hook.
nativeBuildInputs = [ makeWrapper lua ];
});
in env