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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
{lib, config, pkgs, ...}:
let
# names mapped to unique identifiers of calendars
calendars = {
unschedule = "3e40534f-bfb9-b973-f615-f958a6361e95";
ymca-open-swim = "066441A6-B48F-439B-9BD0-5D0FA8F4CB6F";
scheduling = "8fd24d42-2294-9bc3-cece-3922c7cd4d09";
fasting-schedule = "e2ad2353-f91e-76c9-fb0f-2c8722ed9d2a";
ben-shared = "ben";
kate = "0962a74ab76a97543b485d2a583caa271042baab9d64437ae6c3bc8a50df1f08";
training = "eb5dfe0a-0e60-b7e5-eb7a-3b980b50b195";
parasail = "ben.sima@parasail.io";
};
getCals = ls: lib.attrsets.attrVals ls calendars;
common = {
vdirsyncer = {
enable = true;
auth = "basic";
conflictResolution = "remote wins";
metadata = [
"displayname"
"description"
];
timeRange = {
# sync 1 year before and after now
start = "datetime.now() - timedelta(days=365)";
end = "datetime.now() + timedelta(days=365)";
};
};
radicale = {
passwordCommand = ["${pkgs.pass}/bin/pass" "cal.bensima.com"];
type = "caldav";
url = "https://cal.bensima.com";
userName = "ben";
};
khal = {
enable = true;
type = "discover";
};
};
in {
accounts.calendar.basePath = "Calendars";
accounts.calendar.accounts = {
"bensima_personal" = {
primaryCollection = "Unschedule";
remote = common.radicale;
vdirsyncer = common.vdirsyncer // {
collections = getCals ["unschedule" "ymca-open-swim" "fasting-schedule" "training"];
};
khal = common.khal // {
addresses = ["ben@bensima.com" "ben@bsima.me"];
color = "#800080";
};
};
"bensima_scheduling" = {
primaryCollection = "Scheduling";
remote = common.radicale;
vdirsyncer = common.vdirsyncer // {
collections = getCals ["scheduling"];
};
# no khal, just sync this in the background
};
"bensima_shared" = {
remote = common.radicale // {url = "https://cal.bensima.com/shared/ben";};
vdirsyncer = common.vdirsyncer // {collections = getCals ["ben-shared"];};
khal = common.khal // {color = "#097969";};
};
"icloud" = {
remote = {
passwordCommand = ["${pkgs.pass}/bin/pass" "icloud.com/vdirsyncer"];
type = "caldav";
url = "https://caldav.icloud.com";
userName = "bsima@icloud.com";
};
vdirsyncer = common.vdirsyncer // {collections = getCals ["kate"];};
khal = common.khal // {color = "#FAA0A0";};
};
# Parasail Google Calendar - syncs to local for khal viewing
# and for reverse sync to ben-shared
"parasail" = {
remote = {
type = "google_calendar";
};
vdirsyncer = common.vdirsyncer // {
auth = null;
collections = getCals ["parasail"];
itemTypes = ["VEVENT"];
tokenFile = "${config.xdg.dataHome}/vdirsyncer/parasail.token";
clientIdCommand = ["${pkgs.pass}/bin/pass" "parasail/calendar-client-id"];
clientSecretCommand = ["${pkgs.pass}/bin/pass" "parasail/calendar-client-secret"];
};
khal = common.khal // {color = "#4285F4";};
};
};
programs.khal = {
enable = true;
locale = {
# these need to match org-mode formats for khalel
weeknumbers = "left";
timeformat = "%H:%M";
dateformat = "%Y-%m-%d";
longdateformat = "%Y-%m-%d %a";
datetimeformat = "%Y-%m-%d %H:%M";
longdatetimeformat = "%Y-%m-%d %H:%M";
};
};
programs.vdirsyncer.enable = true;
services.vdirsyncer.enable = true;
# autosync ben-shared and scheduling, this must be hand-written and appended
# to the generated config file
services.vdirsyncer.configFile = "${config.xdg.configHome}/vdirsyncer/merged.conf";
xdg.configFile."vdirsyncer/merged.conf".text = let
wrap = s: ''"${s}"'';
join = l: lib.strings.concatStringsSep ", " l;
pair = pre: cals: "[${wrap pre}, ${join (map wrap (getCals cals))}]";
generatedConfig = builtins.readFile "${config.xdg.configFile."vdirsyncer/config".source}";
in ''
${generatedConfig}
### Manual Pairings
[pair shared_to_scheduling]
a = "calendar_bensima_shared_remote"
b = "calendar_bensima_scheduling_remote"
collections = [${pair "a_to_b" ["ben-shared" "scheduling"]}]
conflict_resolution = "a wins"
# One-way sync: ben-shared → parasail Google Calendar
# Uses patched vdirsyncer that skips NotFoundError for missing items
# (works around Google CalDAV bug with recurring events)
[storage calendar_shared_readonly]
type = "filesystem"
path = "${config.home.homeDirectory}/Calendars/bensima_shared"
fileext = ".ics"
read_only = true
[storage calendar_parasail_remote_direct]
type = "google_calendar"
token_file = "${config.xdg.dataHome}/vdirsyncer/parasail.token"
client_id.fetch = ["command", "${pkgs.pass}/bin/pass", "parasail/calendar-client-id"]
client_secret.fetch = ["command", "${pkgs.pass}/bin/pass", "parasail/calendar-client-secret"]
item_types = ["VEVENT"]
[pair shared_to_parasail]
a = "calendar_shared_readonly"
b = "calendar_parasail_remote_direct"
collections = [["ben_to_parasail", "ben", "ben.sima@parasail.io"]]
conflict_resolution = "a wins"
partial_sync = "ignore"
# Reverse sync: parasail → ben-shared (so wife sees work busy times)
[storage calendar_parasail_local_readonly]
type = "filesystem"
path = "${config.home.homeDirectory}/Calendars/parasail"
fileext = ".ics"
read_only = true
[pair parasail_to_shared]
a = "calendar_parasail_local_readonly"
b = "calendar_bensima_shared_remote"
collections = [["parasail_to_ben", "ben.sima@parasail.io", "ben"]]
conflict_resolution = "a wins"
partial_sync = "ignore"
'';
}
|