1{config, lib, pkgs, ...}:
2
3with lib;
4
5let
6
7 cfg = config.services.radicale;
8
9 confFile = pkgs.writeText "radicale.conf" cfg.config;
10
11in
12
13{
14
15 options = {
16
17 services.radicale.enable = mkOption {
18 type = types.bool;
19 default = false;
20 description = ''
21 Enable Radicale CalDAV and CardDAV server
22 '';
23 };
24
25 services.radicale.config = mkOption {
26 type = types.string;
27 default = "";
28 description = ''
29 Radicale configuration, this will set the service
30 configuration file
31 '';
32 };
33 };
34
35 config = mkIf cfg.enable {
36 environment.systemPackages = [ pkgs.pythonPackages.radicale ];
37
38 users.extraUsers = singleton
39 { name = "radicale";
40 uid = config.ids.uids.radicale;
41 description = "radicale user";
42 home = "/var/lib/radicale";
43 createHome = true;
44 };
45
46 users.extraGroups = singleton
47 { name = "radicale";
48 gid = config.ids.gids.radicale;
49 };
50
51 systemd.services.radicale = {
52 description = "A Simple Calendar and Contact Server";
53 after = [ "network-interfaces.target" ];
54 wantedBy = [ "multi-user.target" ];
55 script = "${pkgs.pythonPackages.radicale}/bin/radicale -C ${confFile} -d";
56 serviceConfig.Type = "forking";
57 serviceConfig.User = "radicale";
58 serviceConfig.Group = "radicale";
59 };
60 };
61}