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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
{ pkgs, lib, ... }:
let
radicale_calendars = {
type = "caldav";
url = "http://localhost:5232/";
# Radicale needs username/password.
username = "alice";
password = "password";
};
radicale_contacts = {
type = "carddav";
url = "http://localhost:5232/";
# Radicale needs username/password.
username = "alice";
password = "password";
};
xandikos_calendars = {
type = "caldav";
url = "http://localhost:8080/user/calendars";
# Xandikos warns
# > No current-user-principal returned, re-using URL http://localhost:8080/user/calendars/
# but we do not need username/password.
};
xandikos_contacts = {
type = "carddav";
url = "http://localhost:8080/user/contacts";
};
local_calendars = {
type = "filesystem";
path = "~/calendars";
fileext = ".ics";
};
local_contacts = {
type = "filesystem";
path = "~/contacts";
fileext = ".vcf";
};
mkPairs = a: b: {
calendars = {
a = "${a}_calendars";
b = "${b}_calendars";
collections = [
"from a"
"from b"
];
};
contacts = {
a = "${a}_contacts";
b = "${b}_contacts";
collections = [
"from a"
"from b"
];
};
};
mkRadicaleProps =
tag:
pkgs.writeText "Radicale.props" (
builtins.toJSON {
inherit tag;
}
);
writeLines =
name: eol: lines:
pkgs.writeText name (lib.concatMapStrings (l: "${l}${eol}") lines);
prodid = "-//NixOS test//EN";
dtstamp = "20231129T194743Z";
writeICS =
{
uid,
summary,
dtstart,
dtend,
}:
writeLines "${uid}.ics" "\r\n" [
"BEGIN:VCALENDAR"
"VERSION:2.0"
"PRODID:${prodid}"
"BEGIN:VEVENT"
"UID:${uid}"
"SUMMARY:${summary}"
"DTSTART:${dtstart}"
"DTEND:${dtend}"
"DTSTAMP:${dtstamp}"
"END:VEVENT"
"END:VCALENDAR"
];
foo_ics = writeICS {
uid = "foo";
summary = "Epochalypse";
dtstart = "19700101T000000Z";
dtend = "20380119T031407Z";
};
bar_ics = writeICS {
uid = "bar";
summary = "One Billion Seconds";
dtstart = "19700101T000000Z";
dtend = "20010909T014640Z";
};
writeVCF =
{
uid,
name,
displayName,
email,
}:
writeLines "${uid}.vcf" "\r\n" [
# One of the tools enforces this order of fields.
"BEGIN:VCARD"
"VERSION:4.0"
"UID:${uid}"
"EMAIL;TYPE=INTERNET:${email}"
"FN:${displayName}"
"N:${name}"
"END:VCARD"
];
foo_vcf = writeVCF {
uid = "foo";
name = "Doe;John;;;";
displayName = "John Doe";
email = "john.doe@example.org";
};
bar_vcf = writeVCF {
uid = "bar";
name = "Doe;Jane;;;";
displayName = "Jane Doe";
email = "jane.doe@example.org";
};
in
{
name = "vdirsyncer";
meta.maintainers = with lib.maintainers; [ schnusch ];
nodes = {
machine = {
services.radicale = {
enable = true;
settings.auth.type = "none";
};
services.xandikos = {
enable = true;
extraOptions = [ "--autocreate" ];
};
services.vdirsyncer = {
enable = true;
jobs = {
alice = {
user = "alice";
group = "users";
config = {
statusPath = "/home/alice/.vdirsyncer";
storages = {
inherit
local_calendars
local_contacts
radicale_calendars
radicale_contacts
;
};
pairs = mkPairs "local" "radicale";
};
forceDiscover = true;
};
bob = {
user = "bob";
group = "users";
config = {
statusPath = "/home/bob/.vdirsyncer";
storages = {
inherit
local_calendars
local_contacts
xandikos_calendars
xandikos_contacts
;
};
pairs = mkPairs "local" "xandikos";
};
forceDiscover = true;
};
remote = {
config = {
storages = {
inherit
radicale_calendars
radicale_contacts
xandikos_calendars
xandikos_contacts
;
};
pairs = mkPairs "radicale" "xandikos";
};
forceDiscover = true;
};
};
};
users.users = {
alice.isNormalUser = true;
bob.isNormalUser = true;
};
};
};
testScript = ''
def run_unit(name):
machine.systemctl(f"start {name}")
# The service is Type=oneshot without RemainAfterExit=yes. Once it
# is finished it is no longer active and wait_for_unit will fail.
# When that happens we check if it actually failed.
try:
machine.wait_for_unit(name)
except:
machine.fail(f"systemctl is-failed {name}")
start_all()
machine.wait_for_open_port(5232)
machine.wait_for_open_port(8080)
machine.wait_for_unit("multi-user.target")
with subtest("alice -> radicale"):
# vdirsyncer cannot create create collections on Radicale,
# see https://vdirsyncer.pimutils.org/en/stable/tutorials/radicale.html
machine.succeed("runuser -u radicale -- install -Dm 644 ${mkRadicaleProps "VCALENDAR"} /var/lib/radicale/collections/collection-root/alice/foocal/.Radicale.props")
machine.succeed("runuser -u radicale -- install -Dm 644 ${mkRadicaleProps "VADDRESSBOOK"} /var/lib/radicale/collections/collection-root/alice/foocard/.Radicale.props")
machine.succeed("runuser -u alice -- install -Dm 644 ${foo_ics} /home/alice/calendars/foocal/foo.ics")
machine.succeed("runuser -u alice -- install -Dm 644 ${foo_vcf} /home/alice/contacts/foocard/foo.vcf")
run_unit("vdirsyncer@alice.service")
# test statusPath
machine.succeed("test -d /home/alice/.vdirsyncer")
machine.fail("test -e /var/lib/private/vdirsyncer/alice")
with subtest("bob -> xandikos"):
# I suspect Radicale shares the namespace for calendars and
# contacts, but Xandikos separates them. We just use `barcal` and
# `barcard` with Xandikos as well to avoid conflicts.
machine.succeed("runuser -u bob -- install -Dm 644 ${bar_ics} /home/bob/calendars/barcal/bar.ics")
machine.succeed("runuser -u bob -- install -Dm 644 ${bar_vcf} /home/bob/contacts/barcard/bar.vcf")
run_unit("vdirsyncer@bob.service")
# test statusPath
machine.succeed("test -d /home/bob/.vdirsyncer")
machine.fail("test -e /var/lib/private/vdirsyncer/bob")
with subtest("radicale <-> xandikos"):
# vdirsyncer cannot create create collections on Radicale,
# see https://vdirsyncer.pimutils.org/en/stable/tutorials/radicale.html
machine.succeed("runuser -u radicale -- install -Dm 644 ${mkRadicaleProps "VCALENDAR"} /var/lib/radicale/collections/collection-root/alice/barcal/.Radicale.props")
machine.succeed("runuser -u radicale -- install -Dm 644 ${mkRadicaleProps "VADDRESSBOOK"} /var/lib/radicale/collections/collection-root/alice/barcard/.Radicale.props")
run_unit("vdirsyncer@remote.service")
# test statusPath
machine.succeed("test -d /var/lib/private/vdirsyncer/remote")
with subtest("radicale -> alice"):
run_unit("vdirsyncer@alice.service")
with subtest("xandikos -> bob"):
run_unit("vdirsyncer@bob.service")
with subtest("compare synced files"):
# iCalendar files get reordered
machine.succeed("diff -u --strip-trailing-cr <(sort /home/alice/calendars/foocal/foo.ics) <(sort /home/bob/calendars/foocal/foo.ics) >&2")
machine.succeed("diff -u --strip-trailing-cr <(sort /home/bob/calendars/barcal/bar.ics) <(sort /home/alice/calendars/barcal/bar.ics) >&2")
machine.succeed("diff -u --strip-trailing-cr /home/alice/contacts/foocard/foo.vcf /home/bob/contacts/foocard/foo.vcf >&2")
machine.succeed("diff -u --strip-trailing-cr /home/bob/contacts/barcard/bar.vcf /home/alice/contacts/barcard/bar.vcf >&2")
'';
}
|