I am trying to set up a nix-shell script which contains lua 5.2, the lua sockets library, and a few other libraries. However, when I load the shell, only Lua ends up being present.
with import <nixpkgs> {};
stdenv.mkDerivation rec {
name = "lua-env";
buildInputs = [ lua52Packages.lua lua52Packages.luasocket lua52Packages.luasec lua52Packages.cjson ];
}
When I run the shell, this is what I get:
savanni@lapis:~ $ nix-shell lua.nix
[nix-shell:~]$ lua
Lua 5.2.3 Copyright (C) 1994-2013 Lua.org, PUC-Rio
> require 'socket'
stdin:1: module 'socket' not found:
no field package.preload['socket']
no file '/usr/share/lua/5.2/socket.lua'
no file '/usr/share/lua/5.2/socket/init.lua'
no file '/usr/lib/lua/5.2/socket.lua'
no file '/usr/lib/lua/5.2/socket/init.lua'
no file './socket.lua'
no file '/usr/lib/lua/5.2/socket.so'
no file '/usr/lib/lua/5.2/loadall.so'
no file './socket.so'
stack traceback:
[C]: in function 'require'
stdin:1: in main chunk
[C]: in ?
>
[nix-shell:~]$ exit
savanni@lapis:~ $
You have to set
LUA_PATH
andLUA_CPATH
This
shell.nix
should work,To check that those paths are exported,
There is a simpler way to do this in 2020:
This will put a modified
lua
derivation in your environment where theluasocket
andcjson
derivations fromluaPackages
are included in theLUA_PATH
.So you do not need to mess with
LUA_PATH
orshellHooks
yourself.EDIT:
You can use the
lua.withPackages
function in a nix file as well: