1 { config, lib, pkgs, ... }:
3 cfg = config.services.etesync-dav;
6 options.services.etesync-dav = {
7 enable = lib.mkEnableOption "etesync-dav, end-to-end encrypted sync for contacts, calendars and tasks";
11 default = "localhost";
12 description = "The server host address.";
16 type = lib.types.port;
18 description = "The server host port.";
21 apiUrl = lib.mkOption {
23 default = "https://api.etesync.com/";
24 description = "The url to the etesync API.";
27 openFirewall = lib.mkOption {
29 type = lib.types.bool;
30 description = "Whether to open the firewall for the specified port.";
33 sslCertificate = lib.mkOption {
34 type = lib.types.nullOr lib.types.path;
36 example = "/var/etesync.crt";
38 Path to server SSL certificate. It will be copied into
39 etesync-dav's data directory.
43 sslCertificateKey = lib.mkOption {
44 type = lib.types.nullOr lib.types.path;
46 example = "/var/etesync.key";
48 Path to server SSL certificate key. It will be copied into
49 etesync-dav's data directory.
54 config = lib.mkIf cfg.enable {
55 networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.port ];
57 systemd.services.etesync-dav = {
58 description = "etesync-dav - A CalDAV and CardDAV adapter for EteSync";
59 wants = [ "network-online.target" ];
60 after = [ "network-online.target" ];
61 wantedBy = [ "multi-user.target" ];
62 path = [ pkgs.etesync-dav ];
64 ETESYNC_LISTEN_ADDRESS = cfg.host;
65 ETESYNC_LISTEN_PORT = toString cfg.port;
66 ETESYNC_URL = cfg.apiUrl;
67 ETESYNC_DATA_DIR = "/var/lib/etesync-dav";
73 StateDirectory = "etesync-dav";
74 ExecStart = "${pkgs.etesync-dav}/bin/etesync-dav";
75 ExecStartPre = lib.mkIf (cfg.sslCertificate != null || cfg.sslCertificateKey != null) (
76 pkgs.writers.writeBash "etesync-dav-copy-keys" ''
77 ${lib.optionalString (cfg.sslCertificate != null) ''
78 cp ${toString cfg.sslCertificate} $STATE_DIRECTORY/etesync.crt
80 ${lib.optionalString (cfg.sslCertificateKey != null) ''
81 cp ${toString cfg.sslCertificateKey} $STATE_DIRECTORY/etesync.key
85 Restart = "on-failure";
86 RestartSec = "30min 1s";