nixos/modules/radicale.nix

70 lines
2 KiB
Nix
Raw Normal View History

{
2023-09-21 16:05:17 +02:00
pkgs,
config,
lib,
...
}: let
2021-06-10 20:56:40 +02:00
internalPort = 5232;
cfg = config.services.radicaleWithInfcloud;
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 {
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 = {
hosts = ["[::1]:${builtins.toString internalPort}"];
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";
};
storage = {filesystem_folder = "/var/lib/radicale/collections";};
logging = {mask_passwords = true;};
2021-06-10 20:56:40 +02:00
};
};
# Make sure our service user can access the `htpasswd_filename` file
systemd.services.radicale.serviceConfig.SupplementaryGroups = [config.users.groups.keys.name];
2021-06-10 20:56:40 +02: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";
};
# 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 {
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);
locations."/" = {
proxyPass = "http://[::1]:${builtins.toString internalPort}";
};
2021-06-10 20:56:40 +02:00
};
};
}