summaryrefslogtreecommitdiff
path: root/home-modules/services/vdirsyncer.nix
blob: df76bc82c1afb15501b307bd9df545336430d882 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
{
  config,
  lib,
  ...
}:
let
  cfg = config.homesv.vdirsyncer;
in
{
  options.homesv.vdirsyncer = {
    enable = lib.mkEnableOption "Enable syncing via vdirsyncer";
    user = lib.mkOption { default = config.home.username; };
    server = lib.mkOption { default = "https://webdav.wilkuu.xyz/dav.php"; };
  };
  config = lib.mkIf cfg.enable {
    sops.secrets.webdav_uname = {
      sopsFile = ../../secrets/secrets.yaml;
      key = "${cfg.user}/webdav/username";
    };
    sops.secrets.webdav_pass = {
      sopsFile = ../../secrets/secrets.yaml;
      key = "${cfg.user}/webdav/password";
    };
    services.vdirsyncer = {
      enable = true;
      frequency = "*:0/5"; # About once in 5 minutes
    };

    systemd.user.services.vdirsyncer.unitConfig.After = [ "sops-nix.service" ];

    sops.templates."vdirsyncer_config_${cfg.user}" = {
      content = ''
        [general]
        status_path = "~/.vdirsyncer/status/"

        [pair contacts] 
        a = "contacts_local"
        b = "contacts_remote"
        collections = ["from a", "from b"]

        [storage contacts_local] 
        type = "filesystem"
        path = "~/.contacts/"
        fileext = ".vcf" 

        [storage contacts_remote]
        type = "carddav"
        auth = "digest"
        url = "${cfg.server}"
        username = "${config.sops.placeholder.webdav_uname}"
        password = "${config.sops.placeholder.webdav_pass}"

        [pair calendar] 
        a = "calendar_local"
        b = "calendar_remote"
        collections = ["from a", "from b"]
        metadata = ["color", "displayname"]
        conflict_resolution = "b wins"

        [storage calendar_local] 
        type = "filesystem"
        path = "~/.calendar/"
        fileext = ".ics" 

        [storage calendar_remote]
        type = "caldav"
        auth = "digest"
        url = "${cfg.server}"
        username = "${config.sops.placeholder.webdav_uname}"
        password = "${config.sops.placeholder.webdav_pass}"
      '';
    };
    home.file.".config/vdirsyncer/config" = {
      source =
        config.lib.file.mkOutOfStoreSymlink
          config.sops.templates."vdirsyncer_config_${cfg.user}".path;
    };
  };
}