Can not require vicious when added to lua `withPackages`

I tried to use vicious in a lua interpreter but was not able to. With some other lua package my test worked fine:

$ nix-shell -p "lua.withPackages (p: [p.busted])" --command "lua -e 'print(require[[busted]])'"
table: 0x58b111eff760
$ nix-shell -p "lua.withPackages (p: [p.vicious])" --command "lua -e 'print(require[[vicious]])'"
/nix/store/0ams9cbjhsb1ccphamccr55sqk4ylds4-lua-5.2.4/bin/lua: (command line):1: module 'vicious' not found:
	no field package.preload['vicious']
	no file '/nix/store/0ams9cbjhsb1ccphamccr55sqk4ylds4-lua-5.2.4/share/lua/5.2/vicious.lua'
	no file '/nix/store/0ams9cbjhsb1ccphamccr55sqk4ylds4-lua-5.2.4/share/lua/5.2/vicious/init.lua'
	no file '/nix/store/0ams9cbjhsb1ccphamccr55sqk4ylds4-lua-5.2.4/lib/lua/5.2/vicious.lua'
	no file '/nix/store/0ams9cbjhsb1ccphamccr55sqk4ylds4-lua-5.2.4/lib/lua/5.2/vicious/init.lua'
	no file './vicious.lua'
	no file '/nix/store/0ams9cbjhsb1ccphamccr55sqk4ylds4-lua-5.2.4/lib/lua/5.2/vicious.so'
	no file '/nix/store/0ams9cbjhsb1ccphamccr55sqk4ylds4-lua-5.2.4/lib/lua/5.2/loadall.so'
	no file './vicious.so'
stack traceback:
	[C]: in function 'require'
	(command line):1: in main chunk
	[C]: in ?

I am not sure if I am doing something wrong or if vicious is kind of broken. I can build vicious and busted just fine but the folder structure is different:

$ for p in vicious busted; do nix build --out-link $p nixpkgs#luaPackages.$p; done
$ ls -d1 {vicious,busted}/*/lua/5.2
busted/share/lua/5.2
vicious/lib/lua/5.2

Is this because vicious is meant to be used by awesome wm?

What can I do to use vicious in a standalone lua interpreter?

There was a similar issue request luaPackages.lux-lua: not added to LUA_CPATH when used with withPackages where pkg-config was the resolution, have you tried adding that ?

Yep, it looks like the vicious package doesn’t apply toLuaModule, so it won’t be added to the lua paths properly.

No I did not try this before. But it still does not work for me. Where or how am I supposed to add pkg-config?

I now tried these two and they each produce the same error (module 'vicious' not found):

nix-shell -p 'lua.withPackages (p: [p.vicious])' pkg-config --command "lua -e 'print(require[[vicious]])'"
nix-shell -p 'lua.withPackages (p: [p.vicious pkg-config])' --command "lua -e 'print(require[[vicious]])'"

Is it possible to apply this retroactively? I tried

nix-shell -p 'lua.withPackages (p: [(p.luaLib.toLuaModule p.vicious)])' --command "lua -e 'print(require[[vicious]])'"

to no avail.

Interestingly, I might be holding it wrong, adding pkg-config as in the linked issue also doesn’t change the situation:

nix develop --impure --expr 'let pkgs = import (builtins.getFlake "https://channels.nixos.org/nixos-25.11/nixexprs.tar.xz") {}; in pkgs.mkShell { packages = with pkgs; [ (lua.withPackages( ps: with ps; [ pkg-config lux-lua ])) ]; }' --command bash -c "lua -e 'require[[lux-lua]]'"

Assuming pkg-config goes to nativeBuildInputs aka packages (in nix develop as setup hooks are invoked there only, see , i.e., that comment).

In the end I am not so much interested in a shell but more in the lua interpreter that can load the library. But that is only an aside.

I tried several different versions but they all do not work:

{
  pkgs ? import <nixpkgs> { },
}:
let
  toMod = pkgs.lua.pkgs.luaLib.toLuaModule;
  lib2share =
    luaPkg:
    pkgs.runCommand luaPkg.name { } ''
      mkdir $out
      ln -s ${luaPkg}/lib $out/share
    '';
  luaWithModifiedVicious =
    modifier:
    (pkgs.lua.withPackages (ps: [
      (modifier ps.vicious)
    ])).overrideAttrs
      (oa: {
        nativeBuildInputs = oa.nativeBuildInputs ++ [ pkgs.pkg-config ];
      });
in
{
  a = luaWithModifiedVicious pkgs.lib.id;
  b = luaWithModifiedVicious lib2share;
  c = luaWithModifiedVicious toMod;
}

I had a closer look at the source and it’s simply not packaged in a way that allows it to be require’d by the Lua interpreter.

The installPhase was written about 9 years ago, so it’s probably quite outdated with regard to the current nixpkgs Lua ecosystem.

I’ve opened a tracking issue: luaPackages.vicious: cannot be `require`d when added to `lua.withPackages` · Issue #525569 · NixOS/nixpkgs · GitHub

1 Like

@lucc would you please test this PR: luaPackages.vicious: 2.6.0 -> 2.7.1, build with luarocks by mrcjkb · Pull Request #525665 · NixOS/nixpkgs · GitHub?

Note that you’ll still get an error if the awesomewm Lua API isn’t on the Lua path.

It should also be tested with awesomewm, to make sure it doesn’t break.

Thanks for your work @mrcjk. It works with awesome wm and standalone for me.

1 Like