2014-09-02 16:08:56 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.prosody;
|
|
|
|
|
|
|
|
sslOpts = { ... }: {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
key = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.path;
|
2017-03-01 00:57:02 +00:00
|
|
|
description = "Path to the key file.";
|
2014-09-02 16:08:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
cert = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.path;
|
2017-03-01 00:57:02 +00:00
|
|
|
description = "Path to the certificate file.";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraOptions = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
|
|
|
description = "Extra SSL configuration options.";
|
2014-09-02 16:08:56 +01:00
|
|
|
};
|
2017-03-01 00:57:02 +00:00
|
|
|
|
2014-09-02 16:08:56 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
moduleOpts = {
|
|
|
|
|
|
|
|
roster = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = true;
|
|
|
|
description = "Allow users to have a roster";
|
|
|
|
};
|
|
|
|
|
|
|
|
saslauth = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = true;
|
|
|
|
description = "Authentication for clients and servers. Recommended if you want to log in.";
|
|
|
|
};
|
|
|
|
|
|
|
|
tls = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = true;
|
|
|
|
description = "Add support for secure TLS on c2s/s2s connections";
|
|
|
|
};
|
|
|
|
|
|
|
|
dialback = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = true;
|
|
|
|
description = "s2s dialback support";
|
|
|
|
};
|
|
|
|
|
|
|
|
disco = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = true;
|
|
|
|
description = "Service discovery";
|
|
|
|
};
|
|
|
|
|
|
|
|
legacyauth = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = true;
|
|
|
|
description = "Legacy authentication. Only used by some old clients and bots";
|
|
|
|
};
|
|
|
|
|
|
|
|
version = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = true;
|
|
|
|
description = "Replies to server version requests";
|
|
|
|
};
|
|
|
|
|
|
|
|
uptime = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = true;
|
|
|
|
description = "Report how long server has been running";
|
|
|
|
};
|
|
|
|
|
|
|
|
time = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = true;
|
|
|
|
description = "Let others know the time here on this server";
|
|
|
|
};
|
|
|
|
|
|
|
|
ping = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = true;
|
|
|
|
description = "Replies to XMPP pings with pongs";
|
|
|
|
};
|
|
|
|
|
|
|
|
console = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = false;
|
|
|
|
description = "telnet to port 5582";
|
|
|
|
};
|
|
|
|
|
|
|
|
bosh = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = false;
|
|
|
|
description = "Enable BOSH clients, aka 'Jabber over HTTP'";
|
|
|
|
};
|
|
|
|
|
|
|
|
httpserver = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = false;
|
|
|
|
description = "Serve static files from a directory over HTTP";
|
|
|
|
};
|
|
|
|
|
2014-10-15 02:57:00 +01:00
|
|
|
websocket = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-10-15 02:57:00 +01:00
|
|
|
default = false;
|
|
|
|
description = "Enable WebSocket support";
|
|
|
|
};
|
|
|
|
|
2014-09-02 16:08:56 +01:00
|
|
|
};
|
|
|
|
|
2017-03-01 00:57:02 +00:00
|
|
|
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)}
|
|
|
|
};
|
|
|
|
'';
|
2014-09-02 16:08:56 +01:00
|
|
|
|
|
|
|
vHostOpts = { ... }: {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
# TODO: require attribute
|
|
|
|
domain = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Domain name";
|
|
|
|
};
|
|
|
|
|
2015-03-30 12:45:07 +01:00
|
|
|
enabled = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the virtual host";
|
|
|
|
};
|
|
|
|
|
|
|
|
ssl = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.nullOr (types.submodule sslOpts);
|
2014-09-02 16:08:56 +01:00
|
|
|
default = null;
|
2017-03-01 00:57:02 +00:00
|
|
|
description = "Paths to SSL files";
|
2014-09-02 16:08:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2014-09-02 16:08:56 +01:00
|
|
|
description = "Additional virtual host specific configuration";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.prosody = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the prosody server";
|
|
|
|
};
|
|
|
|
|
|
|
|
allowRegistration = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.bool;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = false;
|
|
|
|
description = "Allow account creation";
|
|
|
|
};
|
|
|
|
|
|
|
|
modules = moduleOpts;
|
|
|
|
|
|
|
|
extraModules = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.listOf types.str;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = [];
|
2017-03-01 00:57:02 +00:00
|
|
|
description = "Enable custom modules";
|
2014-09-02 16:08:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
virtualHosts = mkOption {
|
|
|
|
|
|
|
|
description = "Define the virtual hosts";
|
|
|
|
|
2016-09-11 10:06:35 +01:00
|
|
|
type = with types; loaOf (submodule vHostOpts);
|
2014-09-02 16:08:56 +01:00
|
|
|
|
|
|
|
example = {
|
|
|
|
myhost = {
|
|
|
|
domain = "my-xmpp-example-host.org";
|
2015-03-30 12:45:07 +01:00
|
|
|
enabled = true;
|
2014-09-02 16:08:56 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
default = {
|
|
|
|
localhost = {
|
|
|
|
domain = "localhost";
|
2015-03-30 12:45:07 +01:00
|
|
|
enabled = true;
|
2014-09-02 16:08:56 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
ssl = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.nullOr (types.submodule sslOpts);
|
2014-09-02 16:08:56 +01:00
|
|
|
default = null;
|
2017-03-01 00:57:02 +00:00
|
|
|
description = "Paths to SSL files";
|
2014-09-02 16:08:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
admins = mkOption {
|
2017-03-01 00:57:02 +00:00
|
|
|
type = types.listOf types.str;
|
2014-09-02 16:08:56 +01:00
|
|
|
default = [];
|
2017-03-01 00:57:02 +00:00
|
|
|
example = [ "admin1@example.com" "admin2@example.com" ];
|
|
|
|
description = "List of administrators of the current host";
|
2014-09-02 16:08:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2016-10-23 18:33:41 +01:00
|
|
|
type = types.lines;
|
2017-03-01 00:57:02 +00:00
|
|
|
default = "";
|
2014-09-02 16:08:56 +01:00
|
|
|
description = "Additional prosody configuration";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.prosody ];
|
|
|
|
|
|
|
|
environment.etc."prosody/prosody.cfg.lua".text = ''
|
|
|
|
|
|
|
|
pidfile = "/var/lib/prosody/prosody.pid"
|
|
|
|
|
2015-03-30 12:45:07 +01:00
|
|
|
|
2014-09-02 16:08:56 +01:00
|
|
|
log = "*syslog"
|
|
|
|
|
|
|
|
data_path = "/var/lib/prosody"
|
|
|
|
|
2017-04-11 17:08:51 +01:00
|
|
|
allow_registration = ${boolToString cfg.allowRegistration};
|
2014-09-02 16:08:56 +01:00
|
|
|
|
|
|
|
${ optionalString cfg.modules.console "console_enabled = true;" }
|
|
|
|
|
|
|
|
${ optionalString (cfg.ssl != null) (createSSLOptsStr cfg.ssl) }
|
|
|
|
|
|
|
|
admins = { ${lib.concatStringsSep ", " (map (n: "\"${n}\"") cfg.admins) } };
|
|
|
|
|
|
|
|
modules_enabled = {
|
|
|
|
|
|
|
|
${ lib.concatStringsSep "\n\ \ " (lib.mapAttrsToList
|
|
|
|
(name: val: optionalString val ''"${name}";'')
|
|
|
|
cfg.modules) }
|
|
|
|
|
|
|
|
${ optionalString cfg.allowRegistration "\"register\"\;" }
|
|
|
|
|
|
|
|
${ lib.concatStringsSep "\n" (map (x: "\"${x}\";") cfg.extraModules)}
|
|
|
|
|
|
|
|
"posix";
|
|
|
|
};
|
|
|
|
|
|
|
|
${ cfg.extraConfig }
|
|
|
|
|
|
|
|
${ lib.concatStringsSep "\n" (lib.mapAttrsToList (n: v: ''
|
|
|
|
VirtualHost "${v.domain}"
|
2017-04-11 17:08:51 +01:00
|
|
|
enabled = ${boolToString v.enabled};
|
2014-09-02 16:08:56 +01:00
|
|
|
${ optionalString (v.ssl != null) (createSSLOptsStr v.ssl) }
|
|
|
|
${ v.extraConfig }
|
|
|
|
'') cfg.virtualHosts) }
|
|
|
|
'';
|
|
|
|
|
|
|
|
users.extraUsers.prosody = {
|
|
|
|
uid = config.ids.uids.prosody;
|
|
|
|
description = "Prosody user";
|
|
|
|
createHome = true;
|
|
|
|
group = "prosody";
|
|
|
|
home = "/var/lib/prosody";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups.prosody = {
|
|
|
|
gid = config.ids.gids.prosody;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.prosody = {
|
|
|
|
description = "Prosody XMPP server";
|
2017-02-23 15:05:06 +00:00
|
|
|
after = [ "network-online.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
2014-09-02 16:08:56 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2017-03-01 00:57:02 +00:00
|
|
|
restartTriggers = [ config.environment.etc."prosody/prosody.cfg.lua".source ];
|
2014-09-02 16:08:56 +01:00
|
|
|
serviceConfig = {
|
|
|
|
User = "prosody";
|
2017-03-01 00:57:02 +00:00
|
|
|
Type = "forking";
|
2014-09-02 16:08:56 +01:00
|
|
|
PIDFile = "/var/lib/prosody/prosody.pid";
|
|
|
|
ExecStart = "${pkgs.prosody}/bin/prosodyctl start";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|