luajit2: compiled-in default LUA_PATH lacks /usr/lib/lua - installing nginx-mod-lua makes nginx fail to start (resty.core not found)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 65/100
Research direction
Start by reading lang/lua/luajit2/patches/010-lua-path.patch and compare its compiled-in Lua search paths with the stock lua 5.1 package defaults. Check how nginx-mod-lua-resty-core installs its Lua files under /usr/lib/lua/resty/ and whether the patch adds that directory to package.path. Done when the default search path can find those pure-Lua modules and the nginx Lua module starts without the reported resty.core error.
Written by the indexing model from the issue text.
Description
Maintainer: @javierbrk (luajit2 package)
Environment
- ImmortalWrt SNAPSHOT r42541-2f97ee0c9f, x86_64, kernel 6.18.55 (luajit2 Makefiles are byte-identical between ImmortalWrt and openwrt.git feeds, so this applies upstream as well)
- apk-tools 3.0.5
- nginx-ssl 1.30.5-r1, nginx-mod-lua, nginx-mod-lua-resty-core, nginx-mod-lua-resty-lrucache, luci-nginx
- luajit2 2.1.2026.07.31-r1 (PKG_SOURCE_VERSION 52f52587b37867ab19236eb6917001c2d6b662e7)
Steps to reproduce
- Install
luci-nginx(works fine by itself). apk add nginx-mod-lua(pulls in luajit2 + resty-core packages)./etc/init.d/nginx restart-> nginx enters a procd crash loop, LuCI on 80/443 is down.
Log:
[alert] ... [lua] failed to load the 'resty.core' module ... no file './resty/core.lua'
no file '/usr/share/luajit-2.1/resty/core.lua'
no file '/usr/share/lua/resty/core.lua' (listed twice)
no file './resty/core.so'
no file '/usr/lib/lua/resty/core.so' ...
Root cause
lang/lua/luajit2/patches/010-lua-path.patch rewrites luaconf.h:
-#define LUA_LROOT "/usr/local"
-#define LUA_LUADIR "/lua/5.1/"
+#define LUA_LROOT "/usr"
+#define LUA_LUADIR "/lua/"
Expanding the macros with these values yields the compiled-in defaults (verified against the shipped binary with strings /usr/lib/libluajit-5.1.so.2):
package.path = ./?.lua;/usr/share/luajit-2.1/?.lua;/usr/share/lua/?.lua;/usr/share/lua/?/init.lua;/usr/share/lua/?.lua;/usr/share/lua/?/init.lua
package.cpath = ./?.so;/usr/lib/lua/?.so;/usr/lib/lua/?.so;/usr/lib/lua/loadall.so
/usr/share/luadoes not exist on the target (no package installs there).- All Lua code on OpenWrt lives under
/usr/lib/lua— includingnginx-mod-lua-resty-core, which installslib/resty/*.luato/usr/lib/lua/resty/(net/nginx/Makefile). - The patch adds
/usr/lib/luaonly to cpath (for .so), not to path (for .lua), so pure-Lua modules can never be found.
Contrast with the stock lua 5.1 package (openwrt.git package/utils/lua), whose default package.path includes both /usr/share/lua/?.lua and /usr/lib/lua/?.lua — luajit2 was never aligned with it.
Since lua-nginx-module loads resty.core automatically at http{} initialization (lua_load_resty_core defaults to on) and exits on failure, any nginx build with -mod-lua fails to start out of the box. nginx-util injects no lua_package_path either, so nothing compensates.
The same patch has shipped in the old luajit package since 2018 and was carried over verbatim when luajit2 was added (2023-09).
Suggested fix
Align the luajit2/luajit 010-lua-path.patch with the stock lua package by adding the libdir to the default path as well (OpenWrt installs arch-independent .lua under <prefix>/lib/lua, not <prefix>/share/lua), e.g. redefine LUA_PATH_DEFAULT to also include:
LUA_ROOT "/" LUA_MULTILIB "/lua/?.lua;" LUA_ROOT "/" LUA_MULTILIB "/lua/?/init.lua"
Alternatively, ship a compensating lua_package_path/lua_package_cpath conf snippet with nginx-mod-lua.
Workaround (confirmed working)
/etc/nginx/conf.d/99-lua-paths.conf:
lua_package_path '/usr/share/lua/?.lua;/usr/share/lua/?/init.lua;/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua;;';
lua_package_cpath '/usr/lib/lua/?.so;;';
then /etc/init.d/nginx restart. LuCI comes back immediately.
- Dominant language
- Makefile
- Stars
- 4.7k
- Forks
- 4k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 251
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from openwrt/packages
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
openwrt/packages#31307 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
openwrt/packages#31306 · 1 comment ·
Maintainers usually reply within 1 day
All issues in openwrt/packages
Similar issues
-
bug(core): JsonOutputKeyToolsParser ignores returnId: truePossibly taken A pull request linked to this issue is open or already merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
langchain-ai/langchainjs#12239 ·
Maintainers usually reply within 1 day
-
Board view: the Monitoring column is always empty because compact issue rows drop displayStatusOpen
Difficulty 1/5 Under an hour Newbie friendliness 88/100
paperclipai/paperclip#21837 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
bug(python): read_transaction raises TypeError on a Rewrite with rewritten indicesPossibly taken @Borg93 claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
lance-format/lance#11117 ·
Maintainers usually reply within 2 days
-
[Bug]: time_expr "between november and january" returns an inverted range and matches nothingPossibly taken @KshitijKasodkar claimed this today. Openbug claim-pending triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
doobidoo/mcp-memory-service#2030 · 1 comment ·
Maintainers usually reply within 1 day