2017-07-25 08:01:08 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2014-05-27 21:27:31 +01:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.radicale;
|
|
|
|
|
2021-04-23 19:23:24 +01:00
|
|
|
format = pkgs.formats.ini {
|
|
|
|
listToValue = concatMapStringsSep ", " (generators.mkValueStringDefault { });
|
2017-07-25 08:01:08 +01:00
|
|
|
};
|
2014-05-27 21:27:31 +01:00
|
|
|
|
2021-04-23 19:23:24 +01:00
|
|
|
pkg = if isNull cfg.package then
|
|
|
|
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;
|
|
|
|
|
2021-05-03 17:52:55 +01:00
|
|
|
bindLocalhost = cfg.settings != { } && !hasAttrByPath [ "server" "hosts" ] cfg.settings;
|
|
|
|
|
2021-04-23 19:23:24 +01:00
|
|
|
in {
|
|
|
|
options.services.radicale = {
|
|
|
|
enable = mkEnableOption "Radicale CalDAV and CardDAV server";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
description = "Radicale package to use.";
|
|
|
|
# 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;
|
|
|
|
defaultText = "pkgs.radicale";
|
|
|
|
};
|
2014-05-27 21:27:31 +01:00
|
|
|
|
2021-04-23 19:23:24 +01:00
|
|
|
config = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2014-05-27 21:27:31 +01:00
|
|
|
description = ''
|
2021-04-23 19:23:24 +01:00
|
|
|
Radicale configuration, this will set the service
|
|
|
|
configuration file.
|
|
|
|
This option is mutually exclusive with <option>settings</option>.
|
|
|
|
This option is deprecated. Use <option>settings</option> instead.
|
2017-07-25 08:01:08 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-04-23 19:23:24 +01:00
|
|
|
settings = mkOption {
|
|
|
|
type = format.type;
|
|
|
|
default = { };
|
2017-07-25 08:01:08 +01:00
|
|
|
description = ''
|
2021-04-23 19:23:24 +01:00
|
|
|
Configuration for Radicale. See
|
|
|
|
<link xlink:href="https://radicale.org/3.0.html#documentation/configuration" />.
|
|
|
|
This option is mutually exclusive with <option>config</option>.
|
|
|
|
'';
|
|
|
|
example = literalExample ''
|
|
|
|
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";
|
|
|
|
};
|
2014-05-27 21:27:31 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-04-23 19:23:24 +01:00
|
|
|
rights = mkOption {
|
|
|
|
type = format.type;
|
2014-05-27 21:27:31 +01:00
|
|
|
description = ''
|
2021-04-23 19:23:24 +01:00
|
|
|
Configuration for Radicale's rights file. See
|
|
|
|
<link xlink:href="https://radicale.org/3.0.html#documentation/authentication-and-rights" />.
|
|
|
|
This option only works in conjunction with <option>settings</option>.
|
|
|
|
Setting this will also set <option>settings.rights.type</option> and
|
|
|
|
<option>settings.rights.file</option> to approriate values.
|
|
|
|
'';
|
|
|
|
default = { };
|
|
|
|
example = literalExample ''
|
|
|
|
root = {
|
|
|
|
user = ".+";
|
|
|
|
collection = "";
|
|
|
|
permissions = "R";
|
|
|
|
};
|
|
|
|
principal = {
|
|
|
|
user = ".+";
|
|
|
|
collection = "{user}";
|
|
|
|
permissions = "RW";
|
|
|
|
};
|
|
|
|
calendars = {
|
|
|
|
user = ".+";
|
|
|
|
collection = "{user}/[^/]+";
|
|
|
|
permissions = "rw";
|
|
|
|
};
|
2014-05-27 21:27:31 +01:00
|
|
|
'';
|
2017-07-25 08:01:08 +01:00
|
|
|
};
|
2017-09-18 06:11:23 +01:00
|
|
|
|
2021-04-23 19:23:24 +01:00
|
|
|
extraArgs = mkOption {
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.listOf types.str;
|
2017-09-18 06:11:23 +01:00
|
|
|
default = [];
|
|
|
|
description = "Extra arguments passed to the Radicale daemon.";
|
|
|
|
};
|
2014-05-27 21:27:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-04-23 19:23:24 +01:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.settings == { } || cfg.config == "";
|
|
|
|
message = ''
|
|
|
|
The options services.radicale.config and services.radicale.settings
|
|
|
|
are mutually exclusive.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
warnings = optional (isNull cfg.package && versionOlder config.system.stateVersion "17.09") ''
|
|
|
|
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.
|
|
|
|
'' ++ optional (isNull cfg.package && versionOlder config.system.stateVersion "20.09") ''
|
|
|
|
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 ];
|
2014-05-27 21:27:31 +01:00
|
|
|
|
2021-05-03 17:52:55 +01:00
|
|
|
users.users.radicale.uid = config.ids.uids.radicale;
|
2016-03-20 14:25:02 +00:00
|
|
|
|
2021-05-03 17:52:55 +01:00
|
|
|
users.groups.radicale.gid = config.ids.gids.radicale;
|
2016-03-20 14:25:02 +00:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
systemd.services.radicale = {
|
2014-05-27 21:27:31 +01:00
|
|
|
description = "A Simple Calendar and Contact Server";
|
2016-09-10 19:17:43 +01:00
|
|
|
after = [ "network.target" ];
|
2021-04-23 19:23:24 +01:00
|
|
|
requires = [ "network.target" ];
|
2016-01-06 06:50:18 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2017-07-25 08:01:08 +01:00
|
|
|
serviceConfig = {
|
2017-09-18 06:11:23 +01:00
|
|
|
ExecStart = concatStringsSep " " ([
|
2021-04-23 19:23:24 +01:00
|
|
|
"${pkg}/bin/radicale" "-C" confFile
|
2017-09-18 06:11:23 +01:00
|
|
|
] ++ (
|
|
|
|
map escapeShellArg cfg.extraArgs
|
|
|
|
));
|
2017-07-25 08:01:08 +01:00
|
|
|
User = "radicale";
|
|
|
|
Group = "radicale";
|
2021-05-03 17:52:55 +01:00
|
|
|
StateDirectory = "radicale/collections";
|
|
|
|
StateDirectoryMode = "0750";
|
|
|
|
# Hardening
|
|
|
|
CapabilityBoundingSet = [ "" ];
|
|
|
|
DeviceAllow = [ "/dev/stdin" ];
|
|
|
|
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";
|
2017-07-25 08:01:08 +01:00
|
|
|
};
|
2014-05-27 21:27:31 +01:00
|
|
|
};
|
|
|
|
};
|
2017-03-20 16:13:27 +00:00
|
|
|
|
2021-04-23 19:23:24 +01:00
|
|
|
meta.maintainers = with lib.maintainers; [ aneeshusa infinisil dotlambda ];
|
2014-05-27 21:27:31 +01:00
|
|
|
}
|