From 7b7607382d33457cfda337e6576ccdf4eb1e1c16 Mon Sep 17 00:00:00 2001 From: Luka Blaskovic Date: Sun, 25 Feb 2018 20:48:48 +0000 Subject: [PATCH] lua packages: propagate libs with a setupHook The LUA_PATH and LUA_CPATH variables are needed to load libraries. This setupHook exports them to the environment. --- .../lua-modules/generic/default.nix | 33 ++++++++++++++++++- pkgs/top-level/lua-packages.nix | 6 ++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/pkgs/development/lua-modules/generic/default.nix b/pkgs/development/lua-modules/generic/default.nix index 7152d0b9e360..091ae06ab910 100644 --- a/pkgs/development/lua-modules/generic/default.nix +++ b/pkgs/development/lua-modules/generic/default.nix @@ -1,4 +1,4 @@ -lua: +{ lua, writeText }: { buildInputs ? [], disabled ? false, ... } @ attrs: @@ -19,5 +19,36 @@ else { name = "lua${lua.luaversion}-" + attrs.name; buildInputs = buildInputs ++ [ lua ]; + + setupHook = writeText "setup-hook.sh" '' + # check for lua/clua modules and don't add duplicates + + addLuaLibPath() { + local package_path="$1/share/lua/${lua.luaversion}" + if [[ ! -d $package_path ]]; then return; fi + if [[ $LUA_PATH = *"$package_path"* ]]; then return; fi + + if [[ -z $LUA_PATH ]]; then + export LUA_PATH="$package_path/?.lua" + else + export LUA_PATH="$LUA_PATH;$package_path/?.lua" + fi + } + + addLuaLibCPath() { + local package_cpath="$1/lib/lua/${lua.luaversion}" + if [[ ! -d $package_cpath ]]; then return; fi + if [[ $LUA_CPATH = *"$package_cpath"* ]]; then return; fi + + if [[ -z $LUA_CPATH ]]; then + export LUA_CPATH="$package_cpath/?.so" + else + export LUA_CPATH="$LUA_CPATH;$package_cpath/?.so" + fi + } + + addEnvHooks "$hostOffset" addLuaLibPath + addEnvHooks "$hostOffset" addLuaLibCPath + ''; } ) diff --git a/pkgs/top-level/lua-packages.nix b/pkgs/top-level/lua-packages.nix index d80c43b03f52..a589ceb7e0c9 100644 --- a/pkgs/top-level/lua-packages.nix +++ b/pkgs/top-level/lua-packages.nix @@ -9,7 +9,7 @@ , pcre, oniguruma, gnulib, tre, glibc, sqlite, openssl, expat, cairo , perl, gtk2, python, glib, gobjectIntrospection, libevent, zlib, autoreconfHook , mysql, postgresql, cyrus_sasl -, fetchFromGitHub, libmpack, which, fetchpatch +, fetchFromGitHub, libmpack, which, fetchpatch, writeText }: let @@ -35,7 +35,9 @@ let getLuaCPath = lib : getPath lib "so"; #define build lua package function - buildLuaPackage = callPackage ../development/lua-modules/generic lua; + buildLuaPackage = callPackage ../development/lua-modules/generic { + inherit lua writeText; + }; luarocks = callPackage ../development/tools/misc/luarocks { inherit lua;