1{ lib, pkgs, ... }:
2{
3 name = "syncthing";
4 meta.maintainers = with pkgs.lib.maintainers; [ chkno ];
5
6 nodes = rec {
7 a = {
8 environment.systemPackages = with pkgs; [
9 curl
10 libxml2
11 syncthing
12 ];
13 services.syncthing = {
14 enable = true;
15 openDefaultPorts = true;
16 };
17 };
18 b = a;
19 };
20
21 testScript = ''
22 import json
23 import shlex
24
25 confdir = "/var/lib/syncthing/.config/syncthing"
26
27
28 def addPeer(host, name, deviceID):
29 APIKey = host.succeed(
30 "xmllint --xpath 'string(configuration/gui/apikey)' %s/config.xml" % confdir
31 ).strip()
32 oldConf = host.succeed(
33 "curl -Ssf -H 'X-API-Key: %s' 127.0.0.1:8384/rest/config" % APIKey
34 )
35 conf = json.loads(oldConf)
36 conf["devices"].append({"deviceID": deviceID, "id": name})
37 conf["folders"].append(
38 {
39 "devices": [{"deviceID": deviceID}],
40 "id": "foo",
41 "path": "/var/lib/syncthing/foo",
42 "rescanIntervalS": 1,
43 }
44 )
45 newConf = json.dumps(conf)
46 host.succeed(
47 "curl -Ssf -H 'X-API-Key: %s' 127.0.0.1:8384/rest/config -X PUT -d %s"
48 % (APIKey, shlex.quote(newConf))
49 )
50
51
52 start_all()
53 a.wait_for_unit("syncthing.service")
54 b.wait_for_unit("syncthing.service")
55 a.wait_for_open_port(22000)
56 b.wait_for_open_port(22000)
57
58 aDeviceID = a.succeed("syncthing --home=%s device-id" % confdir).strip()
59 bDeviceID = b.succeed("syncthing --home=%s device-id" % confdir).strip()
60 addPeer(a, "b", bDeviceID)
61 addPeer(b, "a", aDeviceID)
62
63 a.wait_for_file("/var/lib/syncthing/foo")
64 b.wait_for_file("/var/lib/syncthing/foo")
65 a.succeed("echo a2b > /var/lib/syncthing/foo/a2b")
66 b.succeed("echo b2a > /var/lib/syncthing/foo/b2a")
67 a.wait_for_file("/var/lib/syncthing/foo/b2a")
68 b.wait_for_file("/var/lib/syncthing/foo/a2b")
69 '';
70}