Skip to content
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

Lua/luarocks packaging improvements #63108

Merged
merged 9 commits into from
Jun 19, 2019

Conversation

Shados
Copy link
Member

@Shados Shados commented Jun 14, 2019

Motivation for this change

I got annoyed by some issues in the existing luarocks packaging infrastructure while trying to use it.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
    • Well, I used --dry-run and built the attrs separately for easier debugging
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
    • "Relevant documentation" is only up to date in the sense that there is no existing buildLuarocksPackage documentation, something this PR does not change ;).
  • Fits CONTRIBUTING.md.

Details of the changes are given in the commit messages. Broadly:

  • Improved the update-luarocks-packages script
  • Fixed several bugs in and made improvements to buildLuarocksPackages
  • Migrated as many Lua packages as possible from hand-written derivations to generated luarocks-based ones

I've done some history editing to break up the commits into somewhat-logical groupings to make things easier to look through. Interim commits don't necessarily represent a working state for nixpkgs, though.

Some possible issues:

  • prosody's withDBI argument won't work on its own now, as luadbi has been split into the front-end luadbi module and the back-end luadbi-mysql, luadbi-postgresql, and luadbi-sqlite3 modules. I think it should be sufficient to build prosody with arguments like withDBI = true; withExtraLibs = [ lua.pkgs.luadbi-sqlite3 ];, for example, but I don't have a prosody setup to test with.
  • I've removed various Darwin-specific makefile/builder tweaks in the Lua packages that were moved to generated luarocks ones. These should be unnecessary in the new packages, as in each case the package uses luarocks builtin build type, which is theoretically cross-platform. But I don't have a mac to test this assertion with.
  • I've tested that the main executables of each affected package (that has executables) run without throwing related errors, but that's not a guarantee they're working, of course.
  • torchPackages were broken before, and still are now. I spent some time and effort looking into getting them to build, but while most of it isn't too bad, torch itself and some of its dependent torch-specific packages do some fairly wonky things and make bad assumptions in their cmake files.
    • e.g. torch assumes that the location of the lua binary and the install directory for torch are under a shared $PREFIX, and that it is OK to write to the system Lua share directory.
    • They've been broken in unstable for months now. Is anyone actually using this in nixpkgs? @grwlf?

Changes:
- Fetches rocks and builds Nix expressions for them in parallel
- Passes 'maintainers' list to luarocks-nix
- Constructs the luarocks argument list more cleanly, by using an
  indexed array
- Made indentation consistent
Summary of resulting package updates:
- bit32: init at 5.3.0-1 (same as current hand-written derivation)
- busted: 2.0.rc12-1 -> 2.0.rc13-0
- compat53: init at 0.7-1 (same as current hand-written derivation)
- cqueues: init at 20171014-0 (same as current hand-written derivation)
- cyrussasl: init at 1.1.0-1 (same as current hand-written derivation)
- lrexlib-pcre: init at 2.9.0-1 (vs 2.8.0 in current hand-written
  lrexlib derivation)
- luadbi and backends (luadbi-{mysql,postgresql,sqlite3}): init at
  0.7.2-1 (vs 0.7.1 in current hand-written derivation)
- luaexpat: init at 1.3.3-1 (vs 1.3.0 in current hand-written
  derivation)
- luafilesystem: init at 1.7.0-2 (same as current hand-written
  derivation)
- luaossl: init at 20190612-0 (vs 20181207 in current hand-written
  derivation)
- luasec: init at 0.8-1 (same as current hand-written derivation)
- luasocket: init at 3.0rc1-2 (same as current hand-written derivation)
- luasql-sqlite3: init at 2.4.0-1 (vs 2.3.0 in current hand-written
  luasqlite3 derivation)
- rapidjson: 0.5.1-1 -> 0.5.2-1
- stdlib: init at 41.2.2-1 (vs 41.2.1 in current hand-written
  derivation)
The newer version silences some superfluous warnings we were previously
getting in Nix builds using luarocks.
Summary of main changes:
- Now makes use of luarocks dependency resolution (builds will fail if
  rockspec dependencies are unmet)
- Renamed argument `external_deps` -> `exernalDeps` and add
  functionality to handle external dependencies that are multiple-output
  derivations
- Added an `extraVariables` argument for appending to the contents of
  luarocks config `variables` table
- The `rockspecFilename` argument default is now actually used
- The `disabled` argument can now be overriden with a less-restrictive
  check, as it now just sets `meta.broken` instead of throwing an error
  during eval
- The `doCheck` argument is now actually honored if set to `true`
@ofborg ofborg bot added the 6.topic: lua label Jun 14, 2019
@Shados Shados force-pushed the lua-packaging-improvements-pr branch from c31b759 to dd85416 Compare June 14, 2019 02:37
@Shados
Copy link
Member Author

Shados commented Jun 14, 2019

Force-push to fix an eval failure in a broken package -_-''.

luaPackages replaced by generated ones:
- bit32
- compat53
- cqueues
- luacyrussasl -> cyrussasl (luarocks name)
- luaexpat
- luadbi -> luadbi front-end module + separate backend modules
  luadbi-{mysql,postgresql,sqlite3}
- luafilesystem
- luaossl
- luasec
- luasocket
- luastdlib -> stdlib (luarocks name)
- lrexlib -> lrexlib-pcre (we already have lrexlib-gnu and
  lrexlib-posix, lrexlib-pcre however appears to be the variant used in
  mudlet, which is the only current dep in nixpkgs)
- luasqlite -> luasql-sqlite3 (luarocks name)
- lfs -> luafilesytem (we literally had two manually written
  luafilesystem expressions, under different names)

Changes and additions to overrides to generated luarocks packgaes,
including:
- busted: Install bash completions along with the zsh ones
- cqueues:
    - Perform minor surgery on the rockspec to allow using a single
      rockspec to build for all supported Lua versions
    - Add a patch by @vcunat to work around a build issue
- luuid: Wrote a tiny patch to allow for Lua 5.1/Luajit compatibility
- General changes:
    - Sorted the packages
    - Attempted to make the formatting consistent
    - Preferenced `.override` instead of `.overrideAttrs` wherever
      possible

Minor changes to other packages to adjust for the Lua package changes:
- luakit expression simplified
- prosody expression simplified; but users will now need to specify the
  luadbi backend module they intend to use in withExtraLibs
- knot-resolver inputs correctd
- mudlet inputs corrected (although this package was and should still be
  broken)
@Shados
Copy link
Member Author

Shados commented Jun 14, 2019

@teto please take a look, feel free to ping me on IRC if you want to discuss.

@teto teto mentioned this pull request Jun 14, 2019
10 tasks
Copy link
Member

@teto teto left a comment

Choose a reason for hiding this comment

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

wow amazing, thanks a lot for doing this. I've had maybe half of the changes in a tree for a year but never managed to make it into PR material. You seem to have addressed many lingering issues which is great.

For reference:

maintainers/scripts/update-luarocks-packages Outdated Show resolved Hide resolved
maintainers/scripts/luarocks-packages.csv Show resolved Hide resolved
maintainers/scripts/update-luarocks-packages Outdated Show resolved Hide resolved
maintainers/scripts/update-luarocks-packages Outdated Show resolved Hide resolved
maintainers/scripts/update-luarocks-packages Outdated Show resolved Hide resolved
@Shados
Copy link
Member Author

Shados commented Jun 14, 2019

@teto I've added a commit with those changes to update-luarocks-packages 👍.

@teto
Copy link
Member

teto commented Jun 14, 2019

I am all for merging but since it affects lots of packages, I would like some other commiter to run a nix-review on it (too hard on my current setup).

@Shados
Copy link
Member Author

Shados commented Jun 14, 2019

@vcunat or @dtzWill maybe? I know they've done some work with the Lua packaging previously.

@teto
Copy link
Member

teto commented Jun 19, 2019

I ran a nix-review on my small laptop

$ nix build --no-link --keep-going --max-jobs 4 --option build-use-sandbox true -f /home/teto/.cache/nix-review/pr-63108/build.nix
warning: unable to download 'https://cache.nixos.org/nar/1m6mi9lqicbr35dz9f446xzl371x0qndv1fngky6br4va7gd9gkb.nar.xz': HTTP error 200 (curl error: Timeout was reached); retrying in 340 ms
error 9 while decompressing xz file
note: keeping build directory '/tmp/nix-build-cwrap-5.1.drv-0'
builder for '/nix/store/fxqdakkz56rq89mq7lvfzpllanxidczc-cwrap-5.1.drv' failed with exit code 1; last 7 log lines:
 unpacking sources
 unpacking source archive /nix/store/mk5wiijwd5pk7s635xiff4amrcv58vyj-torch-distro-f972c42/pkg/cwrap
 source root is cwrap
 patching sources
 building
 
 Error: Failed finding Lua library. You may need to configure LUA_LIBDIR.
note: keeping build directory '/tmp/nix-build-paths-5.1.drv-0'
builder for '/nix/store/qyfifpyyv0pzfzwcn6ng418sifzkczx3-paths-5.1.drv' failed with exit code 1; last 7 log lines:
 unpacking sources
 unpacking source archive /nix/store/mk5wiijwd5pk7s635xiff4amrcv58vyj-torch-distro-f972c42/pkg/paths
 source root is paths
 patching sources
 building
 
 Error: Failed finding Lua library. You may need to configure LUA_LIBDIR.
cannot build derivation '/nix/store/kbk6lnzxwpl2rvcahsdcm09f4l3gxlnx-torch-5.1.drv': 2 dependencies couldn't be built
cannot build derivation '/nix/store/rk8l0lw47zccsm1nmmnx77hl5dkgn9ik-gnuplot-5.1.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/m5f2bdza1875z97qqqqd2bk58ff07618-graph-5.1.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/4a17a4xjrxh23c5l0bkwb3nzqa8wsag8-optim-5.1.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/mfx6kf1f96bc3hdphcz06i69aly6ll1s-sys-5.1.drv': 3 dependencies couldn't be built
cannot build derivation '/nix/store/c4gfkxvbzsfmrvkmfx2afkm5jm13j42j-xlua-5.1.drv': 4 dependencies couldn't be built
cannot build derivation '/nix/store/mh45f8smp8z2m960aia60sgp1bv9r694-env.drv': 8 dependencies couldn't be built
[304 built (2 failed), 447 copied (2489.2 MiB), 668.5 MiB DL]
error: build of '/nix/store/mh45f8smp8z2m960aia60sgp1bv9r694-env.drv' failed
https://github.com/NixOS/nixpkgs/pull/63108
36 package are marked as broken and were skipped:
lua51Packages.digestif lua52Packages.bit32 lua52Packages.digestif lua52Packages.http lua52Packages.ltermbox lua52Packages.luaposix lua53Packages.bit32 lua53Packages.http lua53Packages.ltermbox lua53Packages.luabitop lua53Packages.luaposix luaPackages.bit32 luaPackages.digestif luaPackages.http luaPackages.ltermbox luaPackages.luaposix luajitPackages.bit32 luajitPackages.digestif luajitPackages.http luajitPackages.ltermbox luajitPackages.luaffi luajitPackages.luaposix mudlet torch-repl torchPackages.dok torchPackages.image torchPackages.itorch torchPackages.lbase64 torchPackages.luaffifb torchPackages.luafilesystem torchPackages.nn torchPackages.nngraph torchPackages.penlight torchPackages.sundown torchPackages.trepl torchPackages.unsup

8 package failed to build:
torchPackages.cwrap torchPackages.gnuplot torchPackages.graph torchPackages.optim torchPackages.paths torchPackages.sys torchPackages.torch torchPackages.xlua

266 package were build:
awesome curseradio deepin.dde-file-manager deepin.deepin-movie-reborn gnome-mpv lua51Packages.ansicolors lua51Packages.argparse lua51Packages.basexx lua51Packages.binaryheap lua51Packages.bit32 lua51Packages.busted lua51Packages.cjson lua51Packages.compat53 lua51Packages.coxpcall lua51Packages.cqueues lua51Packages.cyrussasl lua51Packages.dkjson lua51Packages.fifo lua51Packages.http lua51Packages.inspect lua51Packages.ldoc lua51Packages.lgi lua51Packages.lpeg lua51Packages.lpeg_patterns lua51Packages.lpeglabel lua51Packages.lpty lua51Packages.lrexlib-gnu lua51Packages.lrexlib-pcre lua51Packages.lrexlib-posix lua51Packages.ltermbox lua51Packages.lua-cmsgpack lua51Packages.lua-iconv lua51Packages.lua-lsp lua51Packages.lua-messagepack lua51Packages.lua-term lua51Packages.lua-toml lua51Packages.lua-zlib lua51Packages.lua_cliargs lua51Packages.luabitop lua51Packages.luacheck lua51Packages.luadbi lua51Packages.luadbi-mysql lua51Packages.luadbi-postgresql lua51Packages.luadbi-sqlite3 lua51Packages.luaevent lua51Packages.luaexpat lua51Packages.luaffi lua51Packages.luafilesystem lua51Packages.luaossl lua51Packages.luaposix lua51Packages.luarocks lua51Packages.luarocks-nix lua51Packages.luasec lua51Packages.luasocket lua51Packages.luasql-sqlite3 lua51Packages.luassert lua51Packages.luasystem lua51Packages.luazip lua51Packages.luuid lua51Packages.luv lua51Packages.markdown lua51Packages.mediator_lua lua51Packages.mpack lua51Packages.nvim-client lua51Packages.penlight lua51Packages.rapidjson lua51Packages.say lua51Packages.std__debug lua51Packages.std_normalize lua51Packages.stdlib luaPackages.ansicolors luaPackages.argparse luaPackages.basexx luaPackages.binaryheap luaPackages.busted luaPackages.cjson luaPackages.compat53 luaPackages.coxpcall luaPackages

torchPackages seemed to be broken beforehand, as for lua52Packages.ltermbox or digesti marked as broken, it's more like they should not be available for this interpreter. We might need to change that to make the messages clearer. Anyway it was there before the PR. Important packages seem to build fine even though it might be worth to test them.

@teto teto merged commit c33153b into NixOS:master Jun 19, 2019
@teto
Copy link
Member

teto commented Jun 19, 2019

thanks a lot !

@Izorkin
Copy link
Contributor

Izorkin commented Jun 19, 2019

With this PR error work luadbi

prosody[1399]: sql: Error in SQL transaction: ...j29z9mdhbm4j-lua5.2-luadbi-0.7.2-1/share/lua/5.2/DBI.lua:53: Cannot load driver MySQL. Available drivers are: (None)
prosody[1399]: storage_sql: Unable to read from database accounts store for lafiel: ...j29z9mdhbm4j-lua5.2-luadbi-0.7.2-1/share/lua/5.2/DBI.lua:53: Cannot load driver MySQL. Available drivers are: (None)

Variant with

  nixpkgs.overlays = [
    (self: super: {
      prosody = super.prosody.override {
        withDBI = true;
        withExtraLibs = [ pkgs.luaPackages.luadbi-mysql ];
      };
    })
  ];

not worked

@Shados
Copy link
Member Author

Shados commented Jun 20, 2019

@Izorkin I've opened a PR to fix that. In the mean-time, you could work-around it with e.g.:

{
  nixpkgs.overlays = [
    (self: super: {
      prosody = super.prosody.override {
        withDBI = true;
        withExtraLibs = [
          (super.luaPackages.luadbi-mysql.override({
            extraVariables = ''
              MYSQL_INCDIR='${super.mysql.connector-c}/include/mysql';
              MYSQL_LIBDIR='${super.mysql.connector-c}/lib/mysql';
            '';
          }))
        ];
      };
    })
  ];
}

@Izorkin
Copy link
Contributor

Izorkin commented Jun 20, 2019

With this config - worked!
Prosody with mysql database can be checked through this PR - #63150

@Izorkin
Copy link
Contributor

Izorkin commented Jun 20, 2019

Found new error in Prosody
general error The version of LuaExpat on your system does not support stanza size limits, which may leave servers on untrusted networks (e.g. the internet) vulnerable to denial-of-service attacks. You should upgrade to LuaExpat 1.3.0 or higher as soon as possible. See https://prosody.im/doc/depends#luaexpat for more information.

@Shados
Copy link
Member Author

Shados commented Jun 20, 2019

@Izorkin looks like this is an upstream issue. Based on some investigating, it looks like this is the current official (?) upstream for luaexpat, and is what most distros are using.

The 1.3.0 tarball from there has the same SHA256 as the 1.3.0 tarball in the luaexpat-1.3.0-1 luarock, so I'll make a PR to downgrade to that for now. Longer term, we'll see how things go on the prosody issue tracker for it (I'm subscribed to it now).

In the mean-time, you can override luaexpat that prosody is using on your system like so:

{
  nixpkgs.overlays = [
    (self: super: {
      prosody = super.prosody.override {
        luaexpat = pkgs.luaPackages.luaexpat.override({
          version = "1.3.0-1";

          src = pkgs.fetchurl {
            url    = https://luarocks.org/luaexpat-1.3.0-1.src.rock;
            sha256 = "15jqz5q12i9zvjyagzwz2lrpzya64mih8v1hxwr0wl2gsjh86y5a";
          };
        });
      };
    })
  ];
}

P.S. It would have been very useful to mention you wrote NixOS tests for prosody + mysql when you mentioned the luadbi-mysql issue :P. Could have saved me a bit of time writing a minimal one to test the fix.

@Izorkin
Copy link
Contributor

Izorkin commented Jun 20, 2019

Thanks, worked.

Shados added a commit to Shados/nixpkgs that referenced this pull request Jun 20, 2019
Matches version used on most distros. Fixes an issue with prosody.
Detailed reasoning behind this can be found
[here](NixOS#63108 (comment)).
teto pushed a commit that referenced this pull request Jun 24, 2019
Matches version used on most distros. Fixes an issue with prosody.
Detailed reasoning behind this can be found
[here](#63108 (comment)).
@vcunat
Copy link
Member

vcunat commented Jul 5, 2019

Merging this PR broke auto-setting of variables like $LUA_PATH. One regression is #64174. Another useful property that broke by that is nix-shell usage (lua* won't find the packages). Example test case:

env NIX_PATH=nixpkgs=. nix-shell --pure -p lua luaPackages.http --command 'echo $LUA_PATH'

Works on c33153b^, broken on c33153b.

@vcunat vcunat mentioned this pull request Jul 5, 2019
10 tasks
@teto
Copy link
Member

teto commented Jul 5, 2019

thanks for bisecting.
Might be a good opportunity to have
pkgs/development/lua-modules/generic/default.nix and pkgs/development/interpreters/lua-5/setup- hook.sh converge in terms of how they build LUA_PATH.

@Shados
Copy link
Member Author

Shados commented Jul 5, 2019

@vcunat As @teto pointed to, the issue is that buildLuarocksPackage and buildLuaPackage use different setup hooks, and they populate different variables (NIX_LUA_PATH/CPATH and LUA_PATH/CPATH, respectively). This was always a problem with the buildLuarocksPackage derivations, it just became more obvious now that almost all Lua derivations are using that.

Personally, I think I would prefer converging on the NIX_-prefixed variables, because making use of them is explicitly opt-in. But, that isn't in line with the existing use of similar search path variable hooks (e.g. the Python setup hook directly sets PYTHONPATH), so I believe the correct fix here is:

  • Consolidate both setup hooks into one
  • Set and use the LUA_PATH and LUA_CPATH variables, not the NIX_-prefixed ones

Thoughts?

*: Although the given example is a tad odd... luaPackages.http shouldn't have a LUA_PATH entry, because it doesn't have any Lua lib files (there's a check in both setup hooks for the presence of the directory). It does have Lua shared objects, though, so it should have a LUA_CPATH entry. Typo?

@vcunat
Copy link
Member

vcunat commented Jul 5, 2019

It does have Lua shared objects, though, so it should have a LUA_CPATH entry. Typo?

Up to now the variables were set regardless of the patterns expanding to anything usable, apparently... so it worked for me to bisect the problem. Of course, more real test would be like 6fdd315 or more generally:

--command 'echo require \"http.tls\" | luajit'

@Shados
Copy link
Member Author

Shados commented Jul 6, 2019

@vcunat OK, no, I was confused. It definitely has Lua lib files, and no shared library objects. The variables are only set if the package creates the respective $out/{lib,share}/lua/${lua.luaversion}/ directory, I was just looking at the wrong damn package >.>.

@Shados Shados mentioned this pull request Aug 22, 2019
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants