1 import ./make-test-python.nix ({ lib, pkgs, ... }: {
3 meta.maintainers = with pkgs.lib.maintainers; [ chkno ];
7 environment.systemPackages = with pkgs; [ curl libxml2 syncthing ];
10 openDefaultPorts = true;
20 confdir = "/var/lib/syncthing/.config/syncthing"
23 def addPeer(host, name, deviceID):
24 APIKey = host.succeed(
25 "xmllint --xpath 'string(configuration/gui/apikey)' %s/config.xml" % confdir
27 oldConf = host.succeed(
28 "curl -Ssf -H 'X-API-Key: %s' 127.0.0.1:8384/rest/config" % APIKey
30 conf = json.loads(oldConf)
31 conf["devices"].append({"deviceID": deviceID, "id": name})
32 conf["folders"].append(
34 "devices": [{"deviceID": deviceID}],
36 "path": "/var/lib/syncthing/foo",
40 newConf = json.dumps(conf)
42 "curl -Ssf -H 'X-API-Key: %s' 127.0.0.1:8384/rest/config -X PUT -d %s"
43 % (APIKey, shlex.quote(newConf))
48 a.wait_for_unit("syncthing.service")
49 b.wait_for_unit("syncthing.service")
50 a.wait_for_open_port(22000)
51 b.wait_for_open_port(22000)
53 aDeviceID = a.succeed("syncthing -home=%s -device-id" % confdir).strip()
54 bDeviceID = b.succeed("syncthing -home=%s -device-id" % confdir).strip()
55 addPeer(a, "b", bDeviceID)
56 addPeer(b, "a", aDeviceID)
58 a.wait_for_file("/var/lib/syncthing/foo")
59 b.wait_for_file("/var/lib/syncthing/foo")
60 a.succeed("echo a2b > /var/lib/syncthing/foo/a2b")
61 b.succeed("echo b2a > /var/lib/syncthing/foo/b2a")
62 a.wait_for_file("/var/lib/syncthing/foo/b2a")
63 b.wait_for_file("/var/lib/syncthing/foo/a2b")