2022-03-23 13:10:18 +01:00
|
|
|
{
|
2023-09-21 16:05:17 +02:00
|
|
|
pkgs,
|
2022-03-23 13:10:18 +01:00
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
2021-06-10 20:56:40 +02:00
|
|
|
internalPort = 5232;
|
2022-02-19 16:01:47 +01:00
|
|
|
cfg = config.services.radicaleWithInfcloud;
|
2021-12-16 17:29:40 +01:00
|
|
|
|
2023-09-21 16:05:17 +02:00
|
|
|
sopsPath = key: config.sops.secrets.${key}.path;
|
|
|
|
|
2021-11-03 14:50:37 +01:00
|
|
|
htpasswd_filename = "/etc/radicale/users";
|
2021-06-10 20:56:40 +02:00
|
|
|
in {
|
2022-02-19 16:01:47 +01:00
|
|
|
options.services."radicaleWithInfcloud" = with lib; {
|
|
|
|
enable =
|
|
|
|
mkEnableOption "Radicale service with Infcloud frontend and nginx config";
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services.radicale = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
server = {
|
2022-03-23 13:10:18 +01:00
|
|
|
hosts = ["[::1]:${builtins.toString internalPort}"];
|
2022-02-19 16:01:47 +01:00
|
|
|
max_connections = 8;
|
|
|
|
max_content_length = 100000000;
|
|
|
|
timeout = 30;
|
|
|
|
};
|
|
|
|
auth = {
|
|
|
|
inherit htpasswd_filename;
|
|
|
|
type = "htpasswd";
|
|
|
|
htpasswd_encryption = "bcrypt";
|
|
|
|
delay = 1;
|
|
|
|
};
|
|
|
|
encoding = {
|
|
|
|
request = "utf-8";
|
|
|
|
stock = "utf-8";
|
|
|
|
};
|
2022-03-23 13:10:18 +01:00
|
|
|
storage = {filesystem_folder = "/var/lib/radicale/collections";};
|
|
|
|
logging = {mask_passwords = true;};
|
2021-06-10 20:56:40 +02:00
|
|
|
};
|
|
|
|
};
|
2022-02-19 16:01:47 +01:00
|
|
|
# Make sure our service user can access the `htpasswd_filename` file
|
2022-03-23 13:10:18 +01:00
|
|
|
systemd.services.radicale.serviceConfig.SupplementaryGroups = [config.users.groups.keys.name];
|
2021-06-10 20:56:40 +02:00
|
|
|
|
2022-02-19 16:01:47 +01:00
|
|
|
sops.secrets."radicale-htpasswd" = {
|
|
|
|
owner = config.systemd.services.radicale.serviceConfig.User;
|
|
|
|
mode = "0400";
|
|
|
|
path = htpasswd_filename;
|
|
|
|
};
|
2023-09-21 16:05:17 +02:00
|
|
|
sops.secrets."certificate-key-cal-tammena-me" = {
|
|
|
|
owner = "nginx";
|
|
|
|
mode = "0400";
|
|
|
|
};
|
2022-01-14 17:24:43 +01:00
|
|
|
|
2022-02-19 16:01:47 +01:00
|
|
|
# Enable nginx proxy with ACME
|
2023-09-21 16:05:17 +02:00
|
|
|
services.nginx.virtualHosts."cal.tammena.me" = let
|
|
|
|
certificateName = "cal-tammena-me";
|
|
|
|
in {
|
2022-02-19 16:01:47 +01:00
|
|
|
forceSSL = true;
|
2023-09-21 16:05:17 +02:00
|
|
|
sslTrustedCertificate = pkgs.writeText "ca.crt" (builtins.readFile ../secrets/ca.crt);
|
|
|
|
sslCertificateKey = sopsPath "certificate-key-${certificateName}";
|
|
|
|
sslCertificate = pkgs.writeText "${certificateName}.crt" (builtins.readFile ../secrets/pub/${certificateName}.crt);
|
2022-02-19 16:01:47 +01:00
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://[::1]:${builtins.toString internalPort}";
|
|
|
|
};
|
2021-06-10 20:56:40 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|