NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.2k stars 14.2k forks source link

lua5_1, luajit and original luajit behave differently #189689

Closed junchih closed 6 months ago

junchih commented 2 years ago

Describe the bug

-- "tasting.lua"
print(string.gsub(package.path, ";", "\n").."\n")

Will behave differently on host luajit, nixpkg luajit and nixpkg lua5_1.

Expected behavior

  1. From LUA_PATH_DEFAULT of luaconf.h, there is not way lua runtime will automatically defaultly load something like ./myPkg/init.lua, but lua5_1 of nixpkg 22.05 will do this. I'm new to nix, can't see why?
  2. luajit and lua5_1 of nixpkg 22.05 behave differently. luajit will load all lua module from system path, lua5_1 will load all package from working directory. And both differently with my host luajit, which load module from both working directory and system path.
  3. Anyway, seems same patch both in lua5_1 and luajit, https://github.com/NixOS/nixpkgs/blob/22.05/pkgs/development/interpreters/luajit/default.nix#L62-L69, but luajit doesn't work expectly, so the default luajit from nixpkg 22.05 can't do anything as a standalone lua interpreter.

Screenshots

On macOS 12.5.1, LuaJIT 2.1.0-beta3

./?.lua
/usr/local/share/luajit-2.1.0-beta3/?.lua
/usr/local/share/lua/5.1/?.lua
/usr/local/share/lua/5.1/?/init.lua
/usr/local/share/lua/5.1/?.lua
/usr/local/share/lua/5.1/?/init.lua

On luajit of nixpkgs 22.05 with helping of shell.nix

/nix/store/db6sp8wgr97zn4qyyb7g42yhr00pqjiy-luajit-2.1.0-2022-04-05/share/lua/5.1/?.lua
/nix/store/db6sp8wgr97zn4qyyb7g42yhr00pqjiy-luajit-2.1.0-2022-04-05/share/lua/5.1/?/init.lua

On lua5_1 of nixpkgs 22.05 with helping of shell.nix

./share/lua/5.1/?.lua
./?.lua
./?/init.lua

Notify maintainers

@teto, https://github.com/NixOS/nixpkgs/commit/88842910b52c146bc5ef9c78eed34e5e570ef76c

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
blabla...
blabla...
...
 - system: `"x86_64-darwin"`
 - host os: `Darwin 21.6.0, macOS 10.16`
 - multi-user?: `no`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.3.15`
 - channels(jack): `"nixpkgs-21.11pre306870.67c80531be6"`
 - nixpkgs: `/Users/jack/.nix-defexpr/channels/nixpkgs`
teto commented 2 years ago

The lua ecosystem needs some love see:

The incentive for patching the interpreter is to increase purity and avoid loading inadvertendly stuff from /usr/local/share/. We could always wrap but someone using ";;" (i.e. "add default") in its LUA_PATH could inadvertendly break stuff. What could be interesting is to add your test cases to https://github.com/NixOS/nixpkgs/pull/177556 .

you can use lua.withPackages(p: [ p.cqueues ]); to create a lua with the packages you need.

junchih commented 2 years ago

Sorry, don't have much free time to read all the resources.

Let's see how the issue infects daily development work.

And of course, with correcting LUA_PATH env, this issue could be nonsense. But I don't think some logically unnecessary configurations is good idea for libraries to be portable and maintaining.

teto commented 2 years ago

bottomline was: you are right, things are broken and this is bad. Patches/tests welcomes

teto commented 8 months ago

should be fixed by https://github.com/NixOS/nixpkgs/pull/286822

teto commented 7 months ago

should be fixed on master see those tests https://github.com/NixOS/nixpkgs/blob/6c0dc5723dac06bfa0ebc2f28b3b3a76ad0e9aac/pkgs/development/interpreters/lua-5/tests/default.nix#L42 . I'll let you close once you are confident that fixed the issue