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

Improvements for Prosody #27716

Closed
wants to merge 15 commits into from
Closed
76 changes: 55 additions & 21 deletions nixos/modules/services/networking/prosody.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,98 +10,126 @@ let

options = {

# TODO: require attribute
key = mkOption {
type = types.str;
description = "Path to the key file";
type = types.path;
description = "Path to the key file.";
};

# TODO: require attribute
cert = mkOption {
type = types.str;
description = "Path to the certificate file";
type = types.path;
description = "Path to the certificate file.";
};

extraOptions = mkOption {
type = types.attrs;
default = {};
description = "Extra SSL configuration options.";
};

};
};

moduleOpts = {

roster = mkOption {
type = types.bool;
default = true;
description = "Allow users to have a roster";
};

saslauth = mkOption {
type = types.bool;
default = true;
description = "Authentication for clients and servers. Recommended if you want to log in.";
};

tls = mkOption {
type = types.bool;
default = true;
description = "Add support for secure TLS on c2s/s2s connections";
};

dialback = mkOption {
type = types.bool;
default = true;
description = "s2s dialback support";
};

disco = mkOption {
type = types.bool;
default = true;
description = "Service discovery";
};

legacyauth = mkOption {
type = types.bool;
default = true;
description = "Legacy authentication. Only used by some old clients and bots";
};

version = mkOption {
type = types.bool;
default = true;
description = "Replies to server version requests";
};

uptime = mkOption {
type = types.bool;
default = true;
description = "Report how long server has been running";
};

time = mkOption {
type = types.bool;
default = true;
description = "Let others know the time here on this server";
};

ping = mkOption {
type = types.bool;
default = true;
description = "Replies to XMPP pings with pongs";
};

console = mkOption {
type = types.bool;
default = false;
description = "telnet to port 5582";
};

bosh = mkOption {
type = types.bool;
default = false;
description = "Enable BOSH clients, aka 'Jabber over HTTP'";
};

httpserver = mkOption {
type = types.bool;
default = false;
description = "Serve static files from a directory over HTTP";
};

websocket = mkOption {
type = types.bool;
default = false;
description = "Enable WebSocket support";
};

};

createSSLOptsStr = o:
if o ? key && o ? cert then
''ssl = { key = "${o.key}"; certificate = "${o.cert}"; };''
else "";
toLua = x:
if builtins.isString x then ''"${x}"''
else if builtins.isBool x then toString x
else if builtins.isInt x then toString x
else throw "Invalid Lua value";

createSSLOptsStr = o: ''
ssl = {
key = "${o.key}";
certificate = "${o.cert}";
${concatStringsSep "\n" (mapAttrsToList (name: value: "${name} = ${toLua value};") o.extraOptions)}
};
'';

vHostOpts = { ... }: {

Expand All @@ -114,18 +142,20 @@ let
};

enabled = mkOption {
type = types.bool;
default = false;
description = "Whether to enable the virtual host";
};

ssl = mkOption {
description = "Paths to SSL files";
type = types.nullOr (types.submodule sslOpts);
default = null;
options = [ sslOpts ];
description = "Paths to SSL files";
};

extraConfig = mkOption {
default = '''';
type = types.lines;
default = "";
description = "Additional virtual host specific configuration";
};

Expand All @@ -144,20 +174,23 @@ in
services.prosody = {

enable = mkOption {
type = types.bool;
default = false;
description = "Whether to enable the prosody server";
};

allowRegistration = mkOption {
type = types.bool;
default = false;
description = "Allow account creation";
};

modules = moduleOpts;

extraModules = mkOption {
description = "Enable custom modules";
type = types.listOf types.str;
default = [];
description = "Enable custom modules";
};

virtualHosts = mkOption {
Expand All @@ -183,20 +216,21 @@ in
};

ssl = mkOption {
description = "Paths to SSL files";
type = types.nullOr (types.submodule sslOpts);
default = null;
options = [ sslOpts ];
description = "Paths to SSL files";
};

admins = mkOption {
description = "List of administrators of the current host";
example = [ "admin1@example.com" "admin2@example.com" ];
type = types.listOf types.str;
default = [];
example = [ "admin1@example.com" "admin2@example.com" ];
description = "List of administrators of the current host";
};

extraConfig = mkOption {
type = types.lines;
default = '''';
default = "";
description = "Additional prosody configuration";
};

Expand Down Expand Up @@ -263,17 +297,17 @@ in
};

systemd.services.prosody = {

description = "Prosody XMPP server";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
restartTriggers = [ config.environment.etc."prosody/prosody.cfg.lua".source ];
serviceConfig = {
User = "prosody";
Type = "forking";
PIDFile = "/var/lib/prosody/prosody.pid";
ExecStart = "${pkgs.prosody}/bin/prosodyctl start";
};

};

};
Expand Down
26 changes: 16 additions & 10 deletions pkgs/servers/xmpp/prosody/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{ stdenv, fetchurl, libidn, openssl, makeWrapper, fetchhg
, lua5, luasocket, luasec, luaexpat, luafilesystem, luabitop, luaevent ? null, luazlib ? null
, withLibevent ? true, withZlib ? true }:
, lua5, luasocket, luasec, luaexpat, luafilesystem, luabitop
, withLibevent ? true, luaevent ? null
, withZlib ? true, luazlib ? null
, withDBI ? true, luadbi ? null
, withExtraLibs ? [ ]
, withCommunityModules ? [ ] }:

assert withLibevent -> luaevent != null;
assert withZlib -> luazlib != null;
Expand All @@ -10,7 +14,9 @@ with stdenv.lib;
let
libs = [ luasocket luasec luaexpat luafilesystem luabitop ]
++ optional withLibevent luaevent
++ optional withZlib luazlib;
++ optional withZlib luazlib
++ optional withDBI luadbi
++ withExtraLibs;
getPath = lib : type : "${lib}/lib/lua/${lua5.luaversion}/?.${type};${lib}/share/lua/${lua5.luaversion}/?.${type}";
getLuaPath = lib : getPath lib "lua";
getLuaCPath = lib : getPath lib "so";
Expand All @@ -28,14 +34,12 @@ stdenv.mkDerivation rec {
};

communityModules = fetchhg {
url = "http://prosody-modules.googlecode.com/hg/";
rev = "4b55110b0aa8";
sha256 = "0010x2rl9f9ihy2nwqan2jdlz25433srj2zna1xh10490mc28hij";
url = "https://hg.prosody.im/prosody-modules";
rev = "d48faff92490";
sha256 = "0pmd96nqq7847hkxvlg8721hk47iq99w7b40hjj6srzg35h2jmwn";
};

buildInputs = [ lua5 luasocket luasec luaexpat luabitop libidn openssl makeWrapper ]
++ optional withLibevent luaevent
++ optional withZlib luazlib;
buildInputs = [ lua5 makeWrapper libidn openssl ];

configureFlags = [
"--ostype=linux"
Expand All @@ -44,7 +48,9 @@ stdenv.mkDerivation rec {
];

postInstall = ''
cp $communityModules/mod_websocket/mod_websocket.lua $out/lib/prosody/modules/
${concatMapStringsSep "\n" (module: ''
cp -r $communityModules/mod_${module} $out/lib/prosody/modules/
'') withCommunityModules}
wrapProgram $out/bin/prosody \
--set LUA_PATH '${luaPath};' \
--set LUA_CPATH '${luaCPath};'
Expand Down
2 changes: 1 addition & 1 deletion pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11060,7 +11060,7 @@ with pkgs;

prosody = callPackage ../servers/xmpp/prosody {
lua5 = lua5_1;
inherit (lua51Packages) luasocket luasec luaexpat luafilesystem luabitop luaevent luazlib;
inherit (lua51Packages) luasocket luasec luaexpat luafilesystem luabitop luaevent luazlib luadbi;
};

elasticmq = callPackage ../servers/elasticmq { };
Expand Down