2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.radicale;
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
format = pkgs.formats.ini {
|
|
|
|
listToValue = concatMapStringsSep ", " (generators.mkValueStringDefault { });
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-03-24 00:07:29 +00:00
|
|
|
pkg = if cfg.package == null then
|
2021-05-20 23:08:51 +00:00
|
|
|
pkgs.radicale
|
|
|
|
else
|
|
|
|
cfg.package;
|
|
|
|
|
|
|
|
confFile = if cfg.settings == { } then
|
|
|
|
pkgs.writeText "radicale.conf" cfg.config
|
|
|
|
else
|
|
|
|
format.generate "radicale.conf" cfg.settings;
|
|
|
|
|
|
|
|
rightsFile = format.generate "radicale.rights" cfg.rights;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
bindLocalhost = cfg.settings != { } && !hasAttrByPath [ "server" "hosts" ] cfg.settings;
|
|
|
|
|
|
|
|
in {
|
|
|
|
options.services.radicale = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "Radicale CalDAV and CardDAV server");
|
2021-05-20 23:08:51 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Radicale package to use.";
|
2021-05-20 23:08:51 +00:00
|
|
|
# Default cannot be pkgs.radicale because non-null values suppress
|
|
|
|
# warnings about incompatible configuration and storage formats.
|
|
|
|
type = with types; nullOr package // { inherit (package) description; };
|
|
|
|
default = null;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.radicale";
|
2021-05-20 23:08:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-20 23:08:51 +00:00
|
|
|
Radicale configuration, this will set the service
|
|
|
|
configuration file.
|
2022-08-12 12:06:08 +00:00
|
|
|
This option is mutually exclusive with {option}`settings`.
|
|
|
|
This option is deprecated. Use {option}`settings` instead.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = format.type;
|
|
|
|
default = { };
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-20 23:08:51 +00:00
|
|
|
Configuration for Radicale. See
|
2022-08-12 12:06:08 +00:00
|
|
|
<https://radicale.org/3.0.html#documentation/configuration>.
|
|
|
|
This option is mutually exclusive with {option}`config`.
|
2021-05-20 23:08:51 +00:00
|
|
|
'';
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2021-05-20 23:08:51 +00:00
|
|
|
server = {
|
|
|
|
hosts = [ "0.0.0.0:5232" "[::]:5232" ];
|
|
|
|
};
|
|
|
|
auth = {
|
|
|
|
type = "htpasswd";
|
|
|
|
htpasswd_filename = "/etc/radicale/users";
|
|
|
|
htpasswd_encryption = "bcrypt";
|
|
|
|
};
|
|
|
|
storage = {
|
|
|
|
filesystem_folder = "/var/lib/radicale/collections";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
rights = mkOption {
|
|
|
|
type = format.type;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-20 23:08:51 +00:00
|
|
|
Configuration for Radicale's rights file. See
|
2022-08-12 12:06:08 +00:00
|
|
|
<https://radicale.org/3.0.html#documentation/authentication-and-rights>.
|
|
|
|
This option only works in conjunction with {option}`settings`.
|
|
|
|
Setting this will also set {option}`settings.rights.type` and
|
2022-12-28 21:21:41 +00:00
|
|
|
{option}`settings.rights.file` to appropriate values.
|
2021-05-20 23:08:51 +00:00
|
|
|
'';
|
|
|
|
default = { };
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2021-05-20 23:08:51 +00:00
|
|
|
root = {
|
|
|
|
user = ".+";
|
|
|
|
collection = "";
|
|
|
|
permissions = "R";
|
|
|
|
};
|
|
|
|
principal = {
|
|
|
|
user = ".+";
|
|
|
|
collection = "{user}";
|
|
|
|
permissions = "RW";
|
|
|
|
};
|
|
|
|
calendars = {
|
|
|
|
user = ".+";
|
|
|
|
collection = "{user}/[^/]+";
|
|
|
|
permissions = "rw";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
extraArgs = mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Extra arguments passed to the Radicale daemon.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-05-20 23:08:51 +00:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.settings == { } || cfg.config == "";
|
|
|
|
message = ''
|
|
|
|
The options services.radicale.config and services.radicale.settings
|
|
|
|
are mutually exclusive.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-03-24 00:07:29 +00:00
|
|
|
warnings = optional (cfg.package == null && versionOlder config.system.stateVersion "17.09") ''
|
2021-05-20 23:08:51 +00:00
|
|
|
The configuration and storage formats of your existing Radicale
|
|
|
|
installation might be incompatible with the newest version.
|
|
|
|
For upgrade instructions see
|
|
|
|
https://radicale.org/2.1.html#documentation/migration-from-1xx-to-2xx.
|
|
|
|
Set services.radicale.package to suppress this warning.
|
2023-03-24 00:07:29 +00:00
|
|
|
'' ++ optional (cfg.package == null && versionOlder config.system.stateVersion "20.09") ''
|
2021-05-20 23:08:51 +00:00
|
|
|
The configuration format of your existing Radicale installation might be
|
|
|
|
incompatible with the newest version. For upgrade instructions see
|
|
|
|
https://github.com/Kozea/Radicale/blob/3.0.6/NEWS.md#upgrade-checklist.
|
|
|
|
Set services.radicale.package to suppress this warning.
|
|
|
|
'' ++ optional (cfg.config != "") ''
|
|
|
|
The option services.radicale.config is deprecated.
|
|
|
|
Use services.radicale.settings instead.
|
|
|
|
'';
|
|
|
|
|
|
|
|
services.radicale.settings.rights = mkIf (cfg.rights != { }) {
|
|
|
|
type = "from_file";
|
|
|
|
file = toString rightsFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkg ];
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
users.users.radicale = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "radicale";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
users.groups.radicale = {};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
systemd.services.radicale = {
|
|
|
|
description = "A Simple Calendar and Contact Server";
|
|
|
|
after = [ "network.target" ];
|
2021-05-20 23:08:51 +00:00
|
|
|
requires = [ "network.target" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = concatStringsSep " " ([
|
2021-05-20 23:08:51 +00:00
|
|
|
"${pkg}/bin/radicale" "-C" confFile
|
2020-04-24 23:36:52 +00:00
|
|
|
] ++ (
|
|
|
|
map escapeShellArg cfg.extraArgs
|
|
|
|
));
|
|
|
|
User = "radicale";
|
|
|
|
Group = "radicale";
|
2021-05-20 23:08:51 +00:00
|
|
|
StateDirectory = "radicale/collections";
|
|
|
|
StateDirectoryMode = "0750";
|
|
|
|
# Hardening
|
|
|
|
CapabilityBoundingSet = [ "" ];
|
2022-05-18 14:49:53 +00:00
|
|
|
DeviceAllow = [ "/dev/stdin" "/dev/urandom" ];
|
2021-05-20 23:08:51 +00:00
|
|
|
DevicePolicy = "strict";
|
|
|
|
IPAddressAllow = mkIf bindLocalhost "localhost";
|
|
|
|
IPAddressDeny = mkIf bindLocalhost "any";
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProcSubset = "pid";
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
ReadWritePaths = lib.optional
|
|
|
|
(hasAttrByPath [ "storage" "filesystem_folder" ] cfg.settings)
|
|
|
|
cfg.settings.storage.filesystem_folder;
|
|
|
|
RemoveIPC = true;
|
|
|
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = [ "@system-service" "~@privileged" "~@resources" ];
|
|
|
|
UMask = "0027";
|
2021-12-06 16:07:01 +00:00
|
|
|
WorkingDirectory = "/var/lib/radicale";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [ infinisil dotlambda ];
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|