Skip to content

lua packages: propagate libs with a setupHook #25846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

orbekk
Copy link
Contributor

@orbekk orbekk commented May 17, 2017

The LUA_PATH and LUA_CPATH variables are needed to load libraries. Export them with a setupHook.

This allows using installed libraries directly, e.g.,

nix-shell -p lua -p luaPackages.cjson --command "lua -e '(require "cjson").encode(1)'"

Also fixes some indentation in the lua-modules/generic/default.nix
file as it was inconsistent.

Motivation for this change

Using lua libraries without having to update LUA_PATH and LUA_CPATH manually.

#25830

Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip" See below for breakages.
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

The failures are either broken or not visible on hydra.nixos.org:

luajitPackages.cjson - already broken on hydra
luajitPackages.luaexpat - already broken on hydra
luajitPackages.luazip - already broken on hydra
luajitPackages.lrexlib fail - not on hydra
lua52Packages.lrexlib fail - not on hydra
luajitPackages.mpack fail - disabled on hydra
mudlet fail - disabled on hydra
lua51Packages.lrexlib fail - not on hydra

Sorry, something went wrong.

The LUA_PATH and LUA_CPATH variables are needed to load libraries.
This setupHook exports them to the environment.

This allows using installed libraries directly, e.g.,

nix-instantiate --eval --expr 'with import <nixpkgs> {}; with luaPackages; getLuaCPath cjson'

Also fixes some indentation in the lua-modules/generic/default.nix
file as it was inconsistent.
@mention-bot
Copy link

@orbekk, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vcunat, @fpletz and @Wyvie to be potential reviewers.

@orbekk
Copy link
Contributor Author

orbekk commented May 21, 2017

Hello! As I mentioned above, there are some failures, but I've checked them on Hydra and it looks like they are already failing.

}
)
# The function addToSearchPathWithCustomDelimiter breaks with ";" in
# the search path.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would you use a semi colon instead of a colon?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the format of LUA_PATH: https://www.lua.org/pil/8.1.html

@orbekk
Copy link
Contributor Author

orbekk commented Jun 7, 2017

@FRidh: Do you have any other comments?

@FRidh
Copy link
Member

FRidh commented Jun 7, 2017

@orbekk no I don't. But then again, I'm also not familiar with Lua. Who is maintaining Lua? Did you cc them?

@orbekk
Copy link
Contributor Author

orbekk commented Jun 7, 2017

Pinging @vcunat, @Wyvie

@vcunat
Copy link
Member

vcunat commented Jun 11, 2017

Well, lua isn't in a really maintained state in nixpkgs AFAIK. I know about this PR all the time, but I've just been unable to find enough time for it yet.

@richardipsum
Copy link
Contributor

@orbekk For what it's worth I have cherry picked this commit, on Linux and the lua interpreter still cannot find the cjson lib, here's a paste:

nix@salo:~/badger$ nix-shell -p lua -p luaPackages.cjson --command lua
Lua 5.2.3 Copyright (C) 1994-2013 Lua.org, PUC-Rio

require 'cjson'
stdin:1: module 'cjson' not found:
no field package.preload['cjson']
no file '/usr/share/lua/5.2/cjson.lua'
no file '/usr/share/lua/5.2/cjson/init.lua'
no file '/usr/lib/lua/5.2/cjson.lua'
no file '/usr/lib/lua/5.2/cjson/init.lua'
no file './cjson.lua'
no file '/usr/lib/lua/5.2/cjson.so'
no file '/usr/lib/lua/5.2/loadall.so'
no file './cjson.so'
stack traceback:
[C]: in function 'require'
stdin:1: in main chunk
[C]: in ?

Let me know if there's anything I can help with, I'd be interested in seeing this merged.

@orbekk
Copy link
Contributor Author

orbekk commented Jun 22, 2017

@richardipsum I get the same behavior, but I'm pretty sure I got this to work when I first made the patch. I don't know why it's not propagating the variables.

I'm about to head out on a vacation, so I'll close this PR and continue to work on it later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants