fruitbasket/modules/sogo.nix

87 lines
2.6 KiB
Nix
Raw Normal View History

2023-03-07 17:59:22 +01:00
{ config, pkgs, ... }:
2023-03-01 18:44:56 +01:00
let
sogo-hostname = "mail.${config.fsr.domain}";
2023-03-07 17:59:22 +01:00
domain = config.fsr.domain;
2023-04-13 19:35:10 +02:00
pg-port = toString config.services.postgresql.port;
2023-03-01 18:44:56 +01:00
in
{
2023-04-03 23:14:12 +02:00
sops.secrets.ldap_search = {
owner = config.systemd.services.sogo.serviceConfig.User;
2023-03-07 17:59:22 +01:00
};
sops.secrets.postgres_sogo = {
owner = config.systemd.services.sogo.serviceConfig.User;
};
2023-04-03 23:14:12 +02:00
2023-03-07 17:59:22 +01:00
services = {
sogo = {
enable = true;
language = "German";
extraConfig = ''
2023-04-03 23:05:00 +02:00
WOWorkersCount = 10;
SOGoUserSources = ({
type = ldap;
CNFieldName = cn;
UIDFieldName = uid;
baseDN = "ou = users, dc=ifsr, dc=de";
bindDN = "uid=search, ou=users, dc=ifsr, dc=de";
bindPassword = LDAP_SEARCH;
2023-04-03 23:05:00 +02:00
hostname = "ldap://localhost";
canAuthenticate = YES;
id = directory;
2023-03-07 17:59:22 +01:00
2023-04-03 23:05:00 +02:00
});
2023-04-13 18:52:15 +02:00
SOGoProfileURL = "postgresql://sogo:POSTGRES_PASSWORD@localhost:${pg-port}/sogo/sogo_user_profile";
SOGoFolderInfoURL = "postgreql://sogo:POSTGRES_PASSWORD@localhost:${pg-port}/sogo/sogo_folder_info";
OCSSessionsFolderURL = "postgresql://sogo:POSTGRES_PASSWORD@localhost:${pg-port}/sogo/sogo_sessions_folder";
2023-03-07 17:59:22 +01:00
''; # Hier ist bindPassword noch nicht vollständig
configReplaces = {
2023-04-13 19:35:10 +02:00
"LDAP_SEARCH" = config.sops.secrets.ldap_search.path;
"POSTGRES_PASSWORD" = config.sops.secrets.postgres_sogo.path;
};
vhostName = "${sogo-hostname}";
2023-03-22 11:24:14 +01:00
timezone = "Europe/Berlin";
2023-03-07 17:59:22 +01:00
};
2023-04-13 18:52:15 +02:00
postgresql = {
enable = true;
ensureUsers = [
{
name = "sogo";
ensurePermissions = {
"DATABASE sogo" = "ALL PRIVILEGES";
};
}
];
ensureDatabases = [ "sogo" ];
};
2023-03-07 17:59:22 +01:00
nginx = {
recommendedProxySettings = true;
virtualHosts."${sogo-hostname}" = {
2023-03-07 17:59:22 +01:00
forceSSL = true;
enableACME = true;
locations = {
"/" = {
2023-03-22 12:09:21 +01:00
proxyPass = "http://127.0.0.1:20000";
2023-03-07 17:59:22 +01:00
proxyWebsockets = true;
};
};
};
};
};
systemd.services.sogo.after = [ "sogo-pgsetup.service" ];
2023-03-07 17:59:22 +01:00
systemd.services.sogo-pgsetup = {
description = "Prepare Sogo postgres database";
wantedBy = [ "multi-user.target" ];
after = [ "networking.target" "postgresql.service" ];
serviceConfig.Type = "oneshot";
2023-03-07 17:59:22 +01:00
path = [ pkgs.sudo config.services.postgresql.package ];
script = ''
sudo -u ${config.services.postgresql.superUser} psql -c "ALTER ROLE sogo WITH PASSWORD '$(cat ${config.sops.secrets.postgres_sogo.path})'"
'';
2023-03-22 11:24:14 +01:00
};
}