Help installing a Luarocks package

I’ve been stuck for the past week trying to install a certain Luarocks package, specifically “enet” bindings for lua. I haven’t been able to find any good resources about how to do this. I can use Luarocks locally but when I go to run a program which requires the library, it says libenet.so.7: cannot open shared object file: No such file or directory which I think means it can’t find the base enet library.

But I have enet in my “configuration.nix” so I have no clue why It doesnt find it there.

Any help would be appreciated

Which program are you trying to run, how are you running it, and how did you install it?

My own lua script which uses enet for networking stuff. I made it when I was on ubuntu, but now that I’m on nix I can’t seem to use Luarocks to get it like I did before.

Running it just by “lua script.lua” and I get the same result no matter which lua version I use.

So after even more trial and error, I came across luarocks-nix and used that to generate a .nix script for the package I needed. This does not work on its own though and I had to edit it to add the base enet package. Specifically the propagatedBuildInputs = [ pkgs.enet ]; line.

{ pkgs, lib, buildLuarocksPackage, fetchFromGitHub, fetchurl, luaOlder }:
buildLuarocksPackage {
  pname = "enet";
  version = "1.2-1";
  knownRockspec = (fetchurl {
    url    = "mirror://luarocks/enet-1.2-1.rockspec";
    sha256 = "0jf0qxf3lsrmc1dww7b7i6srqp2cy8caqv9f1rbva7f6rnppxzra";
  }).outPath;
  src = fetchFromGitHub {
    owner = "leafo";
    repo = "lua-enet";
    rev = "v1.2";
    hash = "sha256-GomfJAPbR+y469LuaNPrkab0Wd3xAsAhT4uqbDo8BUA=";
  };

  disabled = luaOlder "5.1";
  propagatedBuildInputs = [ pkgs.enet ];

  meta = {
    homepage = "http://leafo.net/lua-enet";
    description = "A library for doing network communication in Lua";
    license.fullName = "MIT";
  };
}

I then added (luajitPackages.callPackage ./lua-enet.nix {}) to my configuration.nix to load it, and now my script can recognize enet when I run it with luajit.

No clue if this is the correct way, but it works. Hope this saves others the time and frustration I had to go through.

1 Like