Skip to content

Why does luajit's LUA_PATH not include ?;?.lua? #113110

@JJJollyjim

Description

@JJJollyjim

Describe the bug
The LUA_PATH set by luajit's setup hook does not include the default value ?;?.lua (documented here), so relative imports from the current directory do not work.

To Reproduce

Create two files:

==> a.lua <==
print(require('b'))

==> b.lua <==
return "hi!"
~ $ nix-shell -p luajit
[nix-shell:~]$ which luajit
/nix/store/bafy33kb1drwgcdr031vhjl84ls0sni5-luajit-2.1.0-2020-12-28/bin/luajit
[nix-shell:~]$ echo $LUA_PATH
/nix/store/bafy33kb1drwgcdr031vhjl84ls0sni5-luajit-2.1.0-2020-12-28/lib/lua/5.1/?.lua;/nix/store/bafy33kb1drwgcdr031vhjl84ls0sni5-luajit-2.1.0-2020-12-28/share/lua/5.1/?.lua;/nix/store/bafy33kb1drwgcdr031vhjl84ls0sni5-luajit-2.1.0-2020-12-28/share/lua/5.1/?/init.lua;/nix/store/bafy33kb1drwgcdr031vhjl84ls0sni5-luajit-2.1.0-2020-12-28/lib/lua/5.1/?/init.lua
[nix-shell:~]$ luajit a.lua
luajit: a.lua:1: module 'b' not found:
	no field package.preload['b']
	no file '/nix/store/bafy33kb1drwgcdr031vhjl84ls0sni5-luajit-2.1.0-2020-12-28/lib/lua/5.1/b.lua'
	no file '/nix/store/bafy33kb1drwgcdr031vhjl84ls0sni5-luajit-2.1.0-2020-12-28/share/lua/5.1/b.lua'
	no file '/nix/store/bafy33kb1drwgcdr031vhjl84ls0sni5-luajit-2.1.0-2020-12-28/share/lua/5.1/b/init.lua'
	no file '/nix/store/bafy33kb1drwgcdr031vhjl84ls0sni5-luajit-2.1.0-2020-12-28/lib/lua/5.1/b/init.lua'
	no file '/nix/store/bafy33kb1drwgcdr031vhjl84ls0sni5-luajit-2.1.0-2020-12-28/lib/lua/5.1/b.so'
	no file '/nix/store/bafy33kb1drwgcdr031vhjl84ls0sni5-luajit-2.1.0-2020-12-28/share/lua/5.1/b.so'
stack traceback:
	[C]: in function 'require'
	a.lua:1: in main chunk
	[C]: at 0x004062c0

Expected behavior
From a non-nixos system (Arch):

~ $ which luajit
/usr/bin/luajit
~ $ echo $LUA_PATH
# unset
~ $ luajit a.lua
hi

Additional context
For some reason, nix-shell -p luajit sets a LUA_PATH but nix-shell -p lua does not. I don't really understand that.

Notify maintainers
@thoughtpolice @grwlf @vcunat @andir @lblasc

Metadata

  • system: "x86_64-linux"
  • host os: Linux 5.10.15-arch1-1, Arch Linux, noversion
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.4pre20200721_ff314f1
  • channels(root): "nixpkgs-21.03pre246046.41c0f496810"
  • channels(jamie): ""
  • nixpkgs: /home/jamie/Projects/nixpkgs (master)

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken6.topic: luaLua is a powerful, efficient, lightweight, embeddable scripting language.
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions