1 { config, lib, pkgs, ... }:
6 cfg = config.services.etesync-dav;
9 options.services.etesync-dav = {
10 enable = mkEnableOption (lib.mdDoc "etesync-dav");
14 default = "localhost";
15 description = lib.mdDoc "The server host address.";
21 description = lib.mdDoc "The server host port.";
26 default = "https://api.etesync.com/";
27 description = lib.mdDoc "The url to the etesync API.";
30 openFirewall = mkOption {
33 description = lib.mdDoc "Whether to open the firewall for the specified port.";
36 sslCertificate = mkOption {
37 type = types.nullOr types.path;
39 example = "/var/etesync.crt";
40 description = lib.mdDoc ''
41 Path to server SSL certificate. It will be copied into
42 etesync-dav's data directory.
46 sslCertificateKey = mkOption {
47 type = types.nullOr types.path;
49 example = "/var/etesync.key";
50 description = lib.mdDoc ''
51 Path to server SSL certificate key. It will be copied into
52 etesync-dav's data directory.
57 config = mkIf cfg.enable {
58 networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
60 systemd.services.etesync-dav = {
61 description = "etesync-dav - A CalDAV and CardDAV adapter for EteSync";
62 after = [ "network-online.target" ];
63 wantedBy = [ "multi-user.target" ];
64 path = [ pkgs.etesync-dav ];
66 ETESYNC_LISTEN_ADDRESS = cfg.host;
67 ETESYNC_LISTEN_PORT = toString cfg.port;
68 ETESYNC_URL = cfg.apiUrl;
69 ETESYNC_DATA_DIR = "/var/lib/etesync-dav";
75 StateDirectory = "etesync-dav";
76 ExecStart = "${pkgs.etesync-dav}/bin/etesync-dav";
77 ExecStartPre = mkIf (cfg.sslCertificate != null || cfg.sslCertificateKey != null) (
78 pkgs.writers.writeBash "etesync-dav-copy-keys" ''
79 ${optionalString (cfg.sslCertificate != null) ''
80 cp ${toString cfg.sslCertificate} $STATE_DIRECTORY/etesync.crt
82 ${optionalString (cfg.sslCertificateKey != null) ''
83 cp ${toString cfg.sslCertificateKey} $STATE_DIRECTORY/etesync.key
87 Restart = "on-failure";
88 RestartSec = "30min 1s";