Rock Replace

Posted on Nov 9, 2022

I hear federation is cool now. If you’re reading this, start a blog. It’s the hip old new way to have decentralized shitposts.

Lake view

Lately

I’m doubling down on writing the world’s most niche technology blog and bringing you another adventure from the intersection of MUD Clients and NixPkgs. Thrills abound, what can I say.

Mudlet

This time around I was looking into the Mudlet derivation, which seemed to be stalled at 4.15.1 in the unstable NixPkgs channel, while the latest release was 4.16.0. What was the hold-up? Well, SQLite3 support was broken:

[ ERROR ] - Cannot find Lua module sqlite3.
Lua error: error loading module 'luasql.sqlite3' from file.
'/nix/store/ng8m8g0sddihql99nds5z8amd30qiaig-lua-5.1.5-env/lib/lua/5.1/luasql/sqlite3.so':
/nix/store/ng8m8g0sddihql99nds5z8amd30qiaig-lua-5.1.5-env/lib/lua/5.1/luasql/sqlite3.so: 
  undefined symbol: lua_isinteger
Database support will not be available.

After some digging I had a strong theory for the root cause. For Reasons™️ Mudlet only supports Lua 5.1 and the careful observer will note that the missing symbol from the error message, lua_isinteger, only appears in the Lua 5.3 API Docs. The LuaSQL-SQLite3 LuaRocks page lists compatibility with Lua >= 5.1 but a commit from last year relies on a Lua 5.3+ C API feature! How hasn’t this broken anyone else you might ask? Simple: the regression hasn’t been bundled into a release yet. It’s just us folks on the bleeding edge that are getting cut and NixPkgs at the time of writing has the library pinned at a rev that includes the regression. 🔪

An upstream issue was dutifully filed but I wanted to unbreak Mudlet today. First I considered overriding the LuaRocks rev for the problematic lib back to before the regression. There’s even a handy overrides.nix for Lua modules that could have been used for that. I discarded this approach because it would be changing the version for all of Nixpkgs and the blast radius seemed too high; maybe there are Lua 5.3 users happy with the more up-to-date package.

To localize the fix to just Mudlet I took a different approach, using a package override for the Lua derivation used to build the Lua environment with the dependencies Mudlet requires:

  ...
  overrideLua =
    let
      packageOverrides = self: super: {
        # luasql-sqlite3 master branch broke compatibility with lua 5.1. Pin to
        # an earlier commit.
        # https://github.com/lunarmodules/luasql/issues/147
        luasql-sqlite3 = super.luaLib.overrideLuarocks super.luasql-sqlite3
          (drv: {
            version = "2.6.0-1-custom";
            src = fetchFromGitHub {
              owner = "lunarmodules";
              repo = "luasql";
              rev = "8c58fd6ee32faf750daf6e99af015a31402578d1";
              hash = "sha256-XlTB5O81yWCrx56m0cXQp7EFzeOyfNeqGbuiYqMrTUk=";
            };
          });
      };
    in
    lua.override { inherit packageOverrides; };

  luaEnv = overrideLua.withPackages (ps: with ps; [
    luasql-sqlite3
    ...
  ]);
  ...

It worked perfectly. 🎉 No more undefined symbol trouble and Mudlet 4.16.0 is now available in the NixPkgs unstable channel.

Bonus: I also fixed the optional integration to let Mudlet set your activity status in Discord based on the MUD you’re playing. Getting that working was just a matter of wiring a dependency on discord-rpc through to the QT wrapper LD_LIBRARY_PATH.

Thinking about

Candlepin Bowling

Until next time

Sunset view