summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@zancanaro.id.au>2025-09-17 11:07:55 +1000
committerAndreas Enge <andreas@enge.fr>2026-02-18 21:02:26 +0100
commit906b1e13aa5fb939244758c59ea34e1cc738343e (patch)
tree1f9939a68f2cfd322d8ccbd748299878ade4624c /gnu
parentd09dcc30cf283d2a8baf2d402a7ed86bec366196 (diff)
gnu: lua: Introduce GUIX_LUA_{,C}PATH to set default Lua search paths.
Fixes <https://issues.guix.gnu.org/issue/25425>. * gnu/packages/patches/luajit-search-paths.patch: New file. * gnu/packages/patches/lua-5.1-search-paths.patch: New file. * gnu/packages/patches/lua-5.2-search-paths.patch: New file. * gnu/packages/patches/lua-5.3-search-paths.patch: New file. * gnu/packages/patches/lua-5.4-search-paths.patch: New file. * gnu/packages/patches/lua-5.x-search-path-helpers: New file. * gnu/local.mk (dist_patch_DATA): Register them. * gnu/packages/lua.scm (lua-search-paths): New procedure. (lua) [source]: Apply patches. [native-search-paths]: Define using lua-search-paths. (lua-5.4) [source]: Apply patches. [native-search-paths]: Define using lua-search-paths. (lua-5.2) [source]: Apply patches. [native-search-paths]: Define using lua-search-paths. (lua-5.1) [source]: Apply patches. [native-search-paths]: Define using lua-search-paths. (luajit) [source]: Apply patches. [native-search-paths]: Define GUIX_LUA_PATH and GUIX_LUA_CPATH. Change-Id: I8adc08076e615b3dacc10007eae7c1e9b7d527c0 Signed-off-by: Andreas Enge <andreas@enge.fr>
Diffstat (limited to 'gnu')
-rw-r--r--gnu/local.mk6
-rw-r--r--gnu/packages/lua.scm44
-rw-r--r--gnu/packages/patches/lua-5.1-search-paths.patch39
-rw-r--r--gnu/packages/patches/lua-5.2-search-paths.patch42
-rw-r--r--gnu/packages/patches/lua-5.3-search-paths.patch38
-rw-r--r--gnu/packages/patches/lua-5.4-search-paths.patch38
-rw-r--r--gnu/packages/patches/lua-5.x-search-path-helpers.patch62
-rw-r--r--gnu/packages/patches/luajit-search-paths.patch39
8 files changed, 303 insertions, 5 deletions
diff --git a/gnu/local.mk b/gnu/local.mk
index ea3a2888158..195448c6a70 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1864,8 +1864,14 @@ dist_patch_DATA = \
%D%/packages/patches/lua51-pkgconfig.patch \
%D%/packages/patches/luajit-add-riscv64-support.patch \
%D%/packages/patches/lua-liblua-so.patch \
+ %D%/packages/patches/luajit-search-paths.patch \
+ %D%/packages/patches/lua-5.1-search-paths.patch \
+ %D%/packages/patches/lua-5.2-search-paths.patch \
+ %D%/packages/patches/lua-5.3-search-paths.patch \
%D%/packages/patches/lua-5.4-pkgconfig.patch \
%D%/packages/patches/lua-5.4-liblua-so.patch \
+ %D%/packages/patches/lua-5.4-search-paths.patch \
+ %D%/packages/patches/lua-5.x-search-path-helpers.patch \
%D%/packages/patches/luanti-paths.patch \
%D%/packages/patches/lugaru-fix-sound.patch \
%D%/packages/patches/luit-posix.patch \
diff --git a/gnu/packages/lua.scm b/gnu/packages/lua.scm
index fe6d09f5dff..c40e4ed94fe 100644
--- a/gnu/packages/lua.scm
+++ b/gnu/packages/lua.scm
@@ -90,6 +90,16 @@
#:use-module (gnu packages xorg)
#:use-module ((srfi srfi-1) #:hide (zip)))
+(define (lua-search-paths version)
+ (list (search-path-specification
+ (variable "GUIX_LUA_PATH")
+ (separator ";")
+ (files (list (string-append "share/lua/" version))))
+ (search-path-specification
+ (variable "GUIX_LUA_CPATH")
+ (separator ";")
+ (files (list (string-append "lib/lua/" version))))))
+
(define-public lua
(package
(name "lua")
@@ -101,7 +111,9 @@
(sha256
(base32 "1b2qn2rv96nmbm6zab4l877bd4zq7wpwm8drwjiy2ih4jqzysbhc"))
(patches (search-patches "lua-pkgconfig.patch"
- "lua-liblua-so.patch"))))
+ "lua-liblua-so.patch"
+ "lua-5.x-search-path-helpers.patch"
+ "lua-5.3-search-paths.patch"))))
(build-system gnu-build-system)
(inputs (list readline))
(arguments
@@ -125,6 +137,7 @@
(string-append "INSTALL_TOP=" out)
(string-append "INSTALL_MAN=" out
"/share/man/man1"))))))))
+ (native-search-paths (lua-search-paths "5.3"))
(home-page "https://www.lua.org/")
(synopsis "Embeddable scripting language")
(description
@@ -151,7 +164,10 @@ for configuration, scripting, and rapid prototyping.")
(sha256
(base32 "1bi90r9nzmqhjwhr8ysffhmhq30wxxcpqwmbxr33wyaf2npds62g"))
(patches (search-patches "lua-5.4-pkgconfig.patch"
- "lua-5.4-liblua-so.patch"))))))
+ "lua-5.4-liblua-so.patch"
+ "lua-5.x-search-path-helpers.patch"
+ "lua-5.4-search-paths.patch"))))
+ (native-search-paths (lua-search-paths "5.4"))))
(define-public lua-5.2
(package (inherit lua)
@@ -164,7 +180,10 @@ for configuration, scripting, and rapid prototyping.")
(sha256
(base32 "0jwznq0l8qg9wh5grwg07b5cy3lzngvl5m2nl1ikp6vqssmf9qmr"))
(patches (search-patches "lua-pkgconfig.patch"
- "lua-liblua-so.patch"))))))
+ "lua-liblua-so.patch"
+ "lua-5.x-search-path-helpers.patch"
+ "lua-5.2-search-paths.patch"))))
+ (native-search-paths (lua-search-paths "5.2"))))
(define-public lua-5.1
(package (inherit lua)
@@ -177,7 +196,10 @@ for configuration, scripting, and rapid prototyping.")
(base32 "0cskd4w0g6rdm2q8q3i4n1h3j8kylhs3rq8mxwl9vwlmlxbgqh16"))
(patches (search-patches "lua51-liblua-so.patch"
"lua-CVE-2014-5461.patch"
- "lua51-pkgconfig.patch"))))))
+ "lua51-pkgconfig.patch"
+ "lua-5.x-search-path-helpers.patch"
+ "lua-5.1-search-paths.patch"))))
+ (native-search-paths (lua-search-paths "5.1"))))
(define-public luajit
(let ((branch "v2.1")
@@ -193,7 +215,9 @@ for configuration, scripting, and rapid prototyping.")
(file-name (git-file-name name version))
(sha256
(base32
- "0srwk9nmiz8a93f70inq2597ff6xy203ckr4c0k7jcksdixymi9v"))))
+ "0srwk9nmiz8a93f70inq2597ff6xy203ckr4c0k7jcksdixymi9v"))
+ (patches (search-patches "lua-5.x-search-path-helpers.patch"
+ "luajit-search-paths.patch"))))
(build-system gnu-build-system)
(arguments
(list #:tests? #f ; luajit is distributed without tests
@@ -211,6 +235,16 @@ for configuration, scripting, and rapid prototyping.")
(delete 'configure)) ; no configure script
#:make-flags #~(list (string-append "PREFIX="
(assoc-ref %outputs "out")))))
+ (native-search-paths
+ (list (search-path-specification
+ (variable "GUIX_LUA_PATH")
+ (separator ";")
+ (files (list "share/lua/5.1"
+ "share/luajit-2.1")))
+ (search-path-specification
+ (variable "GUIX_LUA_CPATH")
+ (separator ";")
+ (files (list "lib/lua/5.1")))))
(home-page "https://www.luajit.org/")
(synopsis
"Just in time compiler for Lua programming language version 5.1")
diff --git a/gnu/packages/patches/lua-5.1-search-paths.patch b/gnu/packages/patches/lua-5.1-search-paths.patch
new file mode 100644
index 00000000000..dd3cd8135c5
--- /dev/null
+++ b/gnu/packages/patches/lua-5.1-search-paths.patch
@@ -0,0 +1,39 @@
+Change Lua to use GUIX_LUA_PATH and GUIX_LUA_CPATH to construct the default
+LUA_PATH and LUA_CPATH, instead of using hard-coded paths that Guix doesn't
+populate.
+
+These paths don't use Lua's usual '?' path wildcard, and thus are compatible
+with Guix's search-paths mechanism.
+
+This patch uses functions defined in lua-5.x-search-path-helpers.patch.
+
+--- a/src/loadlib.c
++++ b/src/loadlib.c
+@@ -624,5 +624,8 @@
+ {loader_preload, loader_Lua, loader_C, loader_Croot, NULL};
+
++#include "./guixpaths.c"
++
++
+ LUALIB_API int luaopen_package (lua_State *L) {
+ int i;
+ /* create new type _LOADLIB */
+@@ -646,8 +701,16 @@
+ lua_rawseti(L, -2, i+1);
+ }
+ lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */
+- setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */
+- setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */
++
++ /* Calculate default LUA_PATH and LUA_CPATH values from their
++ corresponding GUIX_ environment variables */
++ const char* default_path = guix_path(L); // push default_path
++ const char* default_cpath = guix_cpath(L); // push default_cpath
++ lua_pushvalue(L, -3); // copy the old head of the stack back to the top
++ setpath(L, "path", LUA_PATH, default_path); /* set field `path' */
++ setpath(L, "cpath", LUA_CPATH, default_cpath); /* set field `cpath' */
++ lua_pop(L, 3); // pop our three working values back off the stack
++
+ /* store config information */
+ lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n"
+ LUA_EXECDIR "\n" LUA_IGMARK);
diff --git a/gnu/packages/patches/lua-5.2-search-paths.patch b/gnu/packages/patches/lua-5.2-search-paths.patch
new file mode 100644
index 00000000000..5af36cf1539
--- /dev/null
+++ b/gnu/packages/patches/lua-5.2-search-paths.patch
@@ -0,0 +1,42 @@
+Change Lua to use GUIX_LUA_PATH and GUIX_LUA_CPATH to construct the default
+LUA_PATH and LUA_CPATH, instead of using hard-coded paths that Guix doesn't
+populate.
+
+These paths don't use Lua's usual '?' path wildcard, and thus are compatible
+with Guix's search-paths mechanism.
+
+This patch uses functions defined in lua-5.x-search-path-helpers.patch.
+
+--- a/src/loadlib.c
++++ b/src/loadlib.c
+@@ -687,6 +687,9 @@
+ }
+
+
++#include "./guixpaths.c"
++
++
+ LUAMOD_API int luaopen_package (lua_State *L) {
+ /* create table CLIBS to keep track of loaded C libraries */
+ luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS);
+@@ -702,10 +757,18 @@
+ lua_setfield(L, -3, "loaders"); /* put it in field `loaders' */
+ #endif
+ lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */
++
++ /* Calculate default LUA_PATH and LUA_CPATH values from their
++ corresponding GUIX_ environment variables */
++ const char* default_path = guix_path(L); // push default_path
++ const char* default_cpath = guix_cpath(L); // push default_cpath
++ lua_pushvalue(L, -3); // copy the old head of the stack back to the top
+ /* set field 'path' */
+- setpath(L, "path", LUA_PATHVERSION, LUA_PATH, LUA_PATH_DEFAULT);
++ setpath(L, "path", LUA_PATHVERSION, LUA_PATH, default_path);
+ /* set field 'cpath' */
+- setpath(L, "cpath", LUA_CPATHVERSION, LUA_CPATH, LUA_CPATH_DEFAULT);
++ setpath(L, "cpath", LUA_CPATHVERSION, LUA_CPATH, default_cpath);
++ lua_pop(L, 3); // pop our three working values back off the stack
++
+ /* store config information */
+ lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
+ LUA_EXEC_DIR "\n" LUA_IGMARK "\n");
diff --git a/gnu/packages/patches/lua-5.3-search-paths.patch b/gnu/packages/patches/lua-5.3-search-paths.patch
new file mode 100644
index 00000000000..d72c9a9a27c
--- /dev/null
+++ b/gnu/packages/patches/lua-5.3-search-paths.patch
@@ -0,0 +1,38 @@
+Change Lua to use GUIX_LUA_PATH and GUIX_LUA_CPATH to construct the default
+LUA_PATH and LUA_CPATH, instead of using hard-coded paths that Guix doesn't
+populate.
+
+These paths don't use Lua's usual '?' path wildcard, and thus are compatible
+with Guix's search-paths mechanism.
+
+This patch uses functions defined in lua-5.x-search-path-helpers.patch.
+
+--- a/src/loadlib.c
++++ b/src/loadlib.c
+@@ -764,13 +772,24 @@
+ }
+
+
++#include "./guixpaths.c"
++
++
+ LUAMOD_API int luaopen_package (lua_State *L) {
+ createclibstable(L);
+ luaL_newlib(L, pk_funcs); /* create 'package' table */
+ createsearcherstable(L);
++
+ /* set paths */
++ /* Calculate default LUA_PATH and LUA_CPATH values from their
++ corresponding GUIX_ environment variables */
++ const char* default_path = guix_path(L); // push default_path
++ const char* default_cpath = guix_cpath(L); // push default_cpath
++ lua_pushvalue(L, -3); // copy the old head of the stack back to the top
+- setpath(L, "path", LUA_PATH_VAR, LUA_PATH_DEFAULT);
+- setpath(L, "cpath", LUA_CPATH_VAR, LUA_CPATH_DEFAULT);
++ setpath(L, "path", LUA_PATH_VAR, default_path);
++ setpath(L, "cpath", LUA_CPATH_VAR, default_cpath);
++ lua_pop(L, 3); // pop our three working values back off the stack
++
+ /* store config information */
+ lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
+ LUA_EXEC_DIR "\n" LUA_IGMARK "\n");
diff --git a/gnu/packages/patches/lua-5.4-search-paths.patch b/gnu/packages/patches/lua-5.4-search-paths.patch
new file mode 100644
index 00000000000..d72c9a9a27c
--- /dev/null
+++ b/gnu/packages/patches/lua-5.4-search-paths.patch
@@ -0,0 +1,38 @@
+Change Lua to use GUIX_LUA_PATH and GUIX_LUA_CPATH to construct the default
+LUA_PATH and LUA_CPATH, instead of using hard-coded paths that Guix doesn't
+populate.
+
+These paths don't use Lua's usual '?' path wildcard, and thus are compatible
+with Guix's search-paths mechanism.
+
+This patch uses functions defined in lua-5.x-search-path-helpers.patch.
+
+--- a/src/loadlib.c
++++ b/src/loadlib.c
+@@ -764,13 +772,24 @@
+ }
+
+
++#include "./guixpaths.c"
++
++
+ LUAMOD_API int luaopen_package (lua_State *L) {
+ createclibstable(L);
+ luaL_newlib(L, pk_funcs); /* create 'package' table */
+ createsearcherstable(L);
++
+ /* set paths */
++ /* Calculate default LUA_PATH and LUA_CPATH values from their
++ corresponding GUIX_ environment variables */
++ const char* default_path = guix_path(L); // push default_path
++ const char* default_cpath = guix_cpath(L); // push default_cpath
++ lua_pushvalue(L, -3); // copy the old head of the stack back to the top
+- setpath(L, "path", LUA_PATH_VAR, LUA_PATH_DEFAULT);
+- setpath(L, "cpath", LUA_CPATH_VAR, LUA_CPATH_DEFAULT);
++ setpath(L, "path", LUA_PATH_VAR, default_path);
++ setpath(L, "cpath", LUA_CPATH_VAR, default_cpath);
++ lua_pop(L, 3); // pop our three working values back off the stack
++
+ /* store config information */
+ lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
+ LUA_EXEC_DIR "\n" LUA_IGMARK "\n");
diff --git a/gnu/packages/patches/lua-5.x-search-path-helpers.patch b/gnu/packages/patches/lua-5.x-search-path-helpers.patch
new file mode 100644
index 00000000000..9bcd9fb9e73
--- /dev/null
+++ b/gnu/packages/patches/lua-5.x-search-path-helpers.patch
@@ -0,0 +1,62 @@
+Define two helper functions that are used in other Lua patches.
+
+The functions construct default values for LUA_PATH and LUA_CPATH (using '?'s
+as wildcards) from GUIX_LUA_PATH and GUIX_LUA_CPATH, respectively.
+
+--- /dev/null
++++ b/src/guixpaths.c
+@@ -0,0 +1,54 @@
++const char* guix_path (lua_State* L) {
++ luaL_Buffer buf;
++ luaL_buffinit(L, &buf);
++
++ const char* next;
++ const char* source = getenv("GUIX_LUA_PATH");
++ if (source != NULL) {
++ while ((next = strstr(source, ";")) != NULL) {
++ luaL_addlstring(&buf, source, next - source); /* push prefix */
++ luaL_addstring(&buf, "/?.lua;");
++ luaL_addlstring(&buf, source, next - source); /* push prefix */
++ luaL_addstring(&buf, "/?/init.lua;");
++ source = next + 1; /* continue after the semicolon */
++ }
++ if (*source != '\0') {
++ luaL_addstring(&buf, source);
++ luaL_addstring(&buf, "/?.lua;");
++ luaL_addstring(&buf, source);
++ luaL_addstring(&buf, "/?/init.lua;");
++ }
++ }
++
++ /* Then add the local directory last */
++ luaL_addstring(&buf, "./?.lua;" "./?/init.lua");
++ luaL_pushresult(&buf);
++ return lua_tostring(L, -1);
++}
++
++
++const char* guix_cpath (lua_State* L) {
++ luaL_Buffer buf;
++ luaL_buffinit(L, &buf);
++
++ const char* next;
++ const char* source = getenv("GUIX_LUA_CPATH");
++ if (source != NULL) {
++ while ((next = strstr(source, ";")) != NULL) {
++ luaL_addlstring(&buf, source, next - source); /* push prefix */
++ luaL_addstring(&buf, "/?.so;");
++ source = next + 1; /* continue after the semicolon */
++ }
++ if (*source != '\0') {
++ luaL_addstring(&buf, source);
++ luaL_addstring(&buf, "/?.so;");
++ }
++ }
++
++ /* Then add the local directory last */
++ luaL_addstring(&buf, "./?.so");
++
++ luaL_pushresult(&buf);
++ return lua_tostring(L, -1);
++}
++
diff --git a/gnu/packages/patches/luajit-search-paths.patch b/gnu/packages/patches/luajit-search-paths.patch
new file mode 100644
index 00000000000..f4547395904
--- /dev/null
+++ b/gnu/packages/patches/luajit-search-paths.patch
@@ -0,0 +1,39 @@
+Change LuaJIT to use GUIX_LUA_PATH and GUIX_LUA_CPATH to construct the default
+LUA_PATH and LUA_CPATH, instead of using hard-coded paths that Guix doesn't
+populate.
+
+These paths don't use Lua's usual '?' path wildcard, and thus are compatible
+with Guix's search-paths mechanism.
+
+This patch uses functions defined in lua-5.x-search-path-helpers.patch.
+
+--- a/src/lib_package.c
++++ b/src/lib_package.c
+@@ -590,6 +590,8 @@
+ NULL
+ };
+
++#include "./guixpaths.c"
++
+ LUALIB_API int luaopen_package(lua_State *L)
+ {
+ int i;
+@@ -612,8 +667,16 @@
+ lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
+ noenv = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+- setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT, noenv);
+- setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT, noenv);
++
++ /* Calculate default LUA_PATH and LUA_CPATH values from their
++ corresponding GUIX_ environment variables */
++ const char* default_path = guix_path(L); // push default_path
++ const char* default_cpath = guix_cpath(L); // push default_cpath
++ lua_pushvalue(L, -3); // copy the old head of the stack back to the top
++ setpath(L, "path", LUA_PATH, default_path, noenv);
++ setpath(L, "cpath", LUA_CPATH, default_cpath, noenv);
++ lua_pop(L, 3); // pop our three working values back off the stack
++
+ lua_pushliteral(L, LUA_PATH_CONFIG);
+ lua_setfield(L, -2, "config");
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);