2018-10-01 16:12:56 +01:00
|
|
|
{ lib, config, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.roundcube;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.roundcube = {
|
2018-11-28 16:33:26 +00:00
|
|
|
enable = mkOption {
|
2018-10-11 09:09:29 +01:00
|
|
|
type = types.bool;
|
2018-11-28 16:33:26 +00:00
|
|
|
default = false;
|
2018-10-11 09:09:29 +01:00
|
|
|
description = ''
|
2018-11-28 16:33:26 +00:00
|
|
|
Whether to enable roundcube.
|
|
|
|
|
|
|
|
Also enables nginx virtual host management.
|
2018-10-11 09:09:29 +01:00
|
|
|
Further nginx configuration can be done by adapting <literal>services.nginx.virtualHosts.<name></literal>.
|
|
|
|
See <xref linkend="opt-services.nginx.virtualHosts"/> for further information.
|
|
|
|
'';
|
2018-10-01 16:12:56 +01:00
|
|
|
};
|
|
|
|
|
2018-10-11 09:09:29 +01:00
|
|
|
hostName = mkOption {
|
2018-10-01 16:12:56 +01:00
|
|
|
type = types.str;
|
2018-11-28 16:33:26 +00:00
|
|
|
example = "webmail.example.com";
|
|
|
|
description = "Hostname to use for the nginx vhost";
|
2018-10-01 16:12:56 +01:00
|
|
|
};
|
|
|
|
|
2019-01-31 21:45:14 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.roundcube;
|
|
|
|
|
|
|
|
example = literalExample ''
|
|
|
|
roundcube.withPlugins (plugins: [ plugins.persistent_login ])
|
|
|
|
'';
|
|
|
|
|
|
|
|
description = ''
|
|
|
|
The package which contains roundcube's sources. Can be overriden to create
|
|
|
|
an environment which contains roundcube and third-party plugins.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-10-11 09:09:29 +01:00
|
|
|
database = {
|
|
|
|
username = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "roundcube";
|
|
|
|
description = "Username for the postgresql connection";
|
|
|
|
};
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
2018-11-28 16:33:26 +00:00
|
|
|
description = ''
|
|
|
|
Host of the postgresql server. If this is not set to
|
|
|
|
<literal>localhost</literal>, you have to create the
|
|
|
|
postgresql user and database yourself, with appropriate
|
|
|
|
permissions.
|
|
|
|
'';
|
2018-10-11 09:09:29 +01:00
|
|
|
};
|
|
|
|
password = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Password for the postgresql connection";
|
|
|
|
};
|
|
|
|
dbname = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "roundcube";
|
|
|
|
description = "Name of the postgresql database";
|
|
|
|
};
|
|
|
|
};
|
2018-10-01 16:12:56 +01:00
|
|
|
|
2018-10-11 09:09:29 +01:00
|
|
|
plugins = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
2018-11-28 16:33:26 +00:00
|
|
|
List of roundcube plugins to enable. Currently, only those directly shipped with Roundcube are supported.
|
2018-10-01 16:12:56 +01:00
|
|
|
'';
|
2018-10-11 09:09:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Extra configuration for roundcube webmail instance";
|
2018-10-01 16:12:56 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2018-10-11 09:09:29 +01:00
|
|
|
environment.etc."roundcube/config.inc.php".text = ''
|
|
|
|
<?php
|
2018-10-01 16:12:56 +01:00
|
|
|
|
2018-10-11 09:09:29 +01:00
|
|
|
$config = array();
|
|
|
|
$config['db_dsnw'] = 'pgsql://${cfg.database.username}:${cfg.database.password}@${cfg.database.host}/${cfg.database.dbname}';
|
|
|
|
$config['log_driver'] = 'syslog';
|
|
|
|
$config['max_message_size'] = '25M';
|
|
|
|
$config['plugins'] = [${concatMapStringsSep "," (p: "'${p}'") cfg.plugins}];
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
2018-11-28 16:33:26 +00:00
|
|
|
services.nginx = {
|
2018-10-11 09:09:29 +01:00
|
|
|
enable = true;
|
|
|
|
virtualHosts = {
|
|
|
|
${cfg.hostName} = {
|
|
|
|
forceSSL = mkDefault true;
|
|
|
|
enableACME = mkDefault true;
|
|
|
|
locations."/" = {
|
2019-01-31 21:45:14 +00:00
|
|
|
root = cfg.package;
|
2018-10-11 09:09:29 +01:00
|
|
|
index = "index.php";
|
|
|
|
extraConfig = ''
|
|
|
|
location ~* \.php$ {
|
|
|
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
|
|
|
fastcgi_pass unix:/run/phpfpm/roundcube;
|
|
|
|
include ${pkgs.nginx}/conf/fastcgi_params;
|
|
|
|
include ${pkgs.nginx}/conf/fastcgi.conf;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2018-10-01 16:12:56 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-10-11 09:09:29 +01:00
|
|
|
services.postgresql = mkIf (cfg.database.host == "localhost") {
|
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
|
2018-11-28 16:33:26 +00:00
|
|
|
services.phpfpm.poolConfigs.roundcube = ''
|
2018-10-01 16:12:56 +01:00
|
|
|
listen = /run/phpfpm/roundcube
|
|
|
|
listen.owner = nginx
|
|
|
|
listen.group = nginx
|
|
|
|
listen.mode = 0660
|
|
|
|
user = nginx
|
|
|
|
pm = dynamic
|
|
|
|
pm.max_children = 75
|
|
|
|
pm.start_servers = 2
|
|
|
|
pm.min_spare_servers = 1
|
|
|
|
pm.max_spare_servers = 20
|
|
|
|
pm.max_requests = 500
|
|
|
|
php_admin_value[error_log] = 'stderr'
|
|
|
|
php_admin_flag[log_errors] = on
|
|
|
|
php_admin_value[post_max_size] = 25M
|
|
|
|
php_admin_value[upload_max_filesize] = 25M
|
|
|
|
catch_workers_output = yes
|
2018-10-11 09:09:29 +01:00
|
|
|
'';
|
|
|
|
systemd.services.phpfpm-roundcube.after = [ "roundcube-setup.service" ];
|
|
|
|
|
|
|
|
systemd.services.roundcube-setup = let
|
|
|
|
pgSuperUser = config.services.postgresql.superUser;
|
2019-04-02 15:02:53 +01:00
|
|
|
in mkMerge [
|
|
|
|
(mkIf (cfg.database.host == "localhost") {
|
|
|
|
requires = [ "postgresql.service" ];
|
|
|
|
after = [ "postgresql.service" ];
|
|
|
|
path = [ config.services.postgresql.package ];
|
|
|
|
})
|
|
|
|
{
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
script = ''
|
|
|
|
mkdir -p /var/lib/roundcube
|
|
|
|
if [ ! -f /var/lib/roundcube/db-created ]; then
|
|
|
|
if [ "${cfg.database.host}" = "localhost" ]; then
|
|
|
|
${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql postgres -c "create role ${cfg.database.username} with login password '${cfg.database.password}'";
|
|
|
|
${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql postgres -c "create database ${cfg.database.dbname} with owner ${cfg.database.username}";
|
|
|
|
fi
|
|
|
|
PGPASSWORD=${cfg.database.password} ${pkgs.postgresql}/bin/psql -U ${cfg.database.username} \
|
|
|
|
-f ${cfg.package}/SQL/postgres.initial.sql \
|
|
|
|
-h ${cfg.database.host} ${cfg.database.dbname}
|
|
|
|
touch /var/lib/roundcube/db-created
|
2018-10-11 09:09:29 +01:00
|
|
|
fi
|
2018-11-28 16:33:26 +00:00
|
|
|
|
2019-04-02 15:02:53 +01:00
|
|
|
${pkgs.php}/bin/php ${cfg.package}/bin/update.sh
|
|
|
|
'';
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
}
|
|
|
|
];
|
2018-10-01 16:12:56 +01:00
|
|
|
};
|
|
|
|
}
|