nixpkgs/nixos/modules/services/networking/prosody.nix

329 lines
7.3 KiB
Nix
Raw Normal View History

{ 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.";
};
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.";
};
2017-03-01 00:57:02 +00:00
};
};
moduleOpts = {
roster = mkOption {
2017-03-01 00:57:02 +00:00
type = types.bool;
default = true;
description = "Allow users to have a roster";
};
saslauth = mkOption {
2017-03-01 00:57:02 +00:00
type = types.bool;
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;
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;
default = true;
description = "s2s dialback support";
};
disco = mkOption {
2017-03-01 00:57:02 +00:00
type = types.bool;
default = true;
description = "Service discovery";
};
legacyauth = mkOption {
2017-03-01 00:57:02 +00:00
type = types.bool;
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;
default = true;
description = "Replies to server version requests";
};
uptime = mkOption {
2017-03-01 00:57:02 +00:00
type = types.bool;
default = true;
description = "Report how long server has been running";
};
time = mkOption {
2017-03-01 00:57:02 +00:00
type = types.bool;
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;
default = true;
description = "Replies to XMPP pings with pongs";
};
console = mkOption {
2017-03-01 00:57:02 +00:00
type = types.bool;
default = false;
description = "telnet to port 5582";
};
bosh = mkOption {
2017-03-01 00:57:02 +00:00
type = types.bool;
default = false;
description = "Enable BOSH clients, aka 'Jabber over HTTP'";
};
httpserver = mkOption {
2017-03-01 00:57:02 +00:00
type = types.bool;
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";
};
};
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)}
};
'';
vHostOpts = { ... }: {
options = {
# TODO: require attribute
domain = mkOption {
type = types.str;
description = "Domain name";
};
enabled = mkOption {
2017-03-01 00:57:02 +00:00
type = types.bool;
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);
default = null;
2017-03-01 00:57:02 +00:00
description = "Paths to SSL files";
};
extraConfig = mkOption {
2017-03-01 00:57:02 +00:00
type = types.lines;
default = "";
description = "Additional virtual host specific configuration";
};
};
};
in
{
###### interface
options = {
services.prosody = {
enable = mkOption {
2017-03-01 00:57:02 +00:00
type = types.bool;
default = false;
description = "Whether to enable the prosody server";
};
2018-02-14 13:52:56 +00:00
package = mkOption {
type = types.package;
description = "Prosody package to use";
default = pkgs.prosody;
defaultText = "pkgs.prosody";
example = literalExample ''
pkgs.prosody.override {
withExtraLibs = [ pkgs.luaPackages.lpty ];
withCommunityModules = [ "auth_external" ];
};
'';
};
allowRegistration = mkOption {
2017-03-01 00:57:02 +00:00
type = types.bool;
default = false;
description = "Allow account creation";
};
modules = moduleOpts;
extraModules = mkOption {
2017-03-01 00:57:02 +00:00
type = types.listOf types.str;
default = [];
2017-03-01 00:57:02 +00:00
description = "Enable custom modules";
};
virtualHosts = mkOption {
description = "Define the virtual hosts";
2016-09-11 10:06:35 +01:00
type = with types; loaOf (submodule vHostOpts);
example = {
myhost = {
domain = "my-xmpp-example-host.org";
enabled = true;
};
};
default = {
localhost = {
domain = "localhost";
enabled = true;
};
};
};
ssl = mkOption {
2017-03-01 00:57:02 +00:00
type = types.nullOr (types.submodule sslOpts);
default = null;
2017-03-01 00:57:02 +00:00
description = "Paths to SSL files";
};
admins = mkOption {
2017-03-01 00:57:02 +00:00
type = types.listOf types.str;
default = [];
2017-03-01 00:57:02 +00:00
example = [ "admin1@example.com" "admin2@example.com" ];
description = "List of administrators of the current host";
};
extraConfig = mkOption {
2016-10-23 18:33:41 +01:00
type = types.lines;
2017-03-01 00:57:02 +00:00
default = "";
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"
log = "*syslog"
data_path = "/var/lib/prosody"
2017-04-11 17:08:51 +01:00
allow_registration = ${boolToString cfg.allowRegistration};
${ 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};
${ 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";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
2017-03-01 00:57:02 +00:00
restartTriggers = [ config.environment.etc."prosody/prosody.cfg.lua".source ];
serviceConfig = {
User = "prosody";
2017-03-01 00:57:02 +00:00
Type = "forking";
PIDFile = "/var/lib/prosody/prosody.pid";
2018-02-14 13:52:56 +00:00
ExecStart = "${cfg.package}/bin/prosodyctl start";
};
};
};
}