Prosody with sql backend

I’m new to nix/NixOS. I am trying to setup a prosody server with SQLite backend. But it seems, that a dependency, namely the luadbi SQL driver is missing.

For example, when I try to add a user:

prosodyctl adduser hallo@example.com
sql                 error       Error in SQL transaction: ...c86p9krcivkh4jaa5q-lua5.2-luadbi-0.5/lib/lua/5.2/DBI.lua:52: Cannot load driver SQLite3. Available drivers are: (None)
example.com:storage_sql  error   Unable to read from database accounts store for hallo: ...c86p9krcivkh4jaa5q-lua5.2-luadbi-0.5/lib/lua/5.2/DBI.lua:52: Cannot load driver SQLite3. Available drivers are: (None)

My setup looks like this:

environment.systemPackages = with pkgs; [
    sqlite
    lua52Packages.luasqlite3
    (pkgs.prosody.override {
      withDBI = true; # is the default anyway, I believe?
    })
  ];

services.prosody = {                                                                                                        
    enable = true;                                                                                                            
    modules = {                                                                                                               
      carbons = true;                                                                                                         
      mam = true;                                                                                                                                                                                                              
      pep = true;                                                                                                             
    };                                                                                                                        
                                                                                                                              
    extraConfig = ''
      authentication = "internal_hashed"
      storage = "sql"
      sql = { driver = "SQLite3", database = "prosody.sqlite" }
    '';
}

What am I missing?

I tried using luadbi without prosody (straight lua 5.2) and had a bunch of errors. I tried using luadbi with lua 5.1 and had no errors.

I created a container to test out prosody and the following seems to work for me:

{ config, lib, pkgs, ... }:

with lib;
let
  prosody_lua51 = pkgs.callPackage <nixpkgs/pkgs/servers/xmpp/prosody> {
    lua5 = pkgs.lua51Packages.lua;
    inherit (pkgs.lua51Packages) luasocket luasec luaexpat luafilesystem luabitop luaevent luadbi;
  };
in  
{ boot.isContainer = true;
  networking.hostName = mkDefault "prosody";
  networking.useDHCP = false;

  services.prosody.enable = true;
  services.prosody.package = prosody_lua51;
}

I think that should work. Let me know.

Thanks for the answer! It seems to work! Lua 5.1 is recommended anyway.

Let me digest first, what you did. Nix’s documentation is all over the place. It’s clear to me, that you somehow modify the prosdoy package in place. But not entirely clear how, yet.

I intuitively did something like

services.prosody = {
  enable = true;
  package = prosody_lua51.override {
    withCommunityModules = [ "auth_sql" "http_upload" "migrate" "smacks" "csi" "cloud_notify" ];
  };

etc
}

which seems to work, because I need the withCommunityModules. Is this the way to go?

Glad to hear it worked out. I think there is a bug with the NixOS luadbi package for lua 5.2 and that is the issue.

In regards to your question, first of all make sure you have a clear distinction between Nix packages and options in your mind. The prosody package is simply a software package that Nix can install onto your system and your could run if you want to, whereas the prosody options in NixOS will actually configure and run the prosody package as a system service.

The prosody_lua51 variable I defined was literally a copy+paste of how the prosody package is defined in NixOS, with the lua version changed from 5.2 to 5.1 (see nixpkgs/pkgs/top-level/all-packages.nix). This makes an new package which is a variant of the existing prosody package.

A common pattern in NixOS options for services is that many services will add a “package” option so you can still use the service provided by NixOS, but you can tell that service to use your own customized version of software. This is what the prosody.package = prosody_lua51; bit was about.

You could just add the withCommunityModules bit to your original prosody_lua51 package definition and save yourself the override. In fact you could even just anonymously pass the new package into prosody.packages and save the declare if you really wanted to, like so:

services.prosody.enable = true;
services.prosody.package = pkgs.callPackage <nixpkgs/pkgs/servers/xmpp/prosody> {
  lua5 = pkgs.lua51Packages.lua;
  withCommunityModules = [ "auth_sql" "http_upload" "migrate" "smacks" "csi" "cloud_notify" ];
  inherit (pkgs.lua51Packages) luasocket luasec luaexpat luafilesystem luabitop luaevent luadbi;
};

I hope this answers your questions.

2 Likes