Syncthing Accept Incoming Shares Declaratively

I’m trying to set up Syncthing, but I can’t find any reference to how I can accept incoming shares. I can accept them in the WebUI, but I’d rather want to do this declaratively, cause that’s the new thang;)

Here’s my config

services = {
    syncthing = {
      enable = true;
      dataDir = "/home/b0ef/.syncthing-data-dir-delme"; #default sync dir, used?
      configDir = "/home/b0ef/.config/syncthing";
      openDefaultPorts = true;
      guiAddress = "";
      declarative = {
        # override any device or directory added or deleted through the WebUI
        overrideDevices = true;     
        overrideFolders = true;     
        devices = {
          "device1" = { id = "NA-NA-WQG3S3C-VT4OQJS-75TCLK4-TWYEFYA-SVFOC57-HHT2ZQN"; };
          #"device2" = { id = "NA-NA-WQG3S3C-VT4OQJS-75TCLK4-TWYEFYA-SVFOC57-EET2ZQN"; };
        folders = {
          "quasar-syncthing" = {
            path = "/home/b0ef/syncthing";
            devices = [ "device1" ];
            versioning = { 
              type = "staggered"; 
              params = { 
                cleanInterval = "3600"; 
                maxAge = "15768000";
              #avoid syncing file permissions
              #ignorePerms = false;
1 Like

Well, if you know the IDs of the folders and the machines you want to share with, you can add them to your config before you get the invite. But then you would send out the invite instead of waiting for it.

There is no “auto accept from machine xyz” when you want to do things purely declarative, as this would have to update your config and trigger a rebuild + activation.

1 Like

Was going to say this pretty much.

However, it would be feasible for syncthing to generate Nix code for an incoming request that you could then copy-paste.

I don’t think it’s likely they’d want to integrate such a niche feature, but perhaps you could make a script that does this if syncthing has an API.

It does, and you could get a JSON description of the incoming request which (probably) contains enough info to then generate the corresponding nix.

Another idea would be a more general conversion tool… Parse the syncthing config.xml and emit the corresponding nix data (that would then regenerate to ~the same config).

Also, from the OP, note that this attribute … doesn’t exist; all that stuff just goes directly under services.syncthing

1 Like

Not sure I understand. I already have defined a share on one system and I want to put that share in the config of another system, so that I don’t have to do anything interactive;)

Then just declare the same share on both, adjusting any local paths and “share with” settings accordingly for each end

I don’t really get how to do that. I would need something like “shared_with” and “shared_from” to declare it?

the …folders.<name>.devices list is the list of other servers to share with. You need to set that to [ "serverA" ] on serverB, and vice-versa (in the simplest case, there might of course be additional devices participating in the share).

All of this is regular syncthing configuration, expressed in nix and wrapping the rest api to set config on startup.<name>.devices&from=0&size=50&sort=alpha_asc&query=services.syncthing

I understand that I specify the device I want to share the folder with, but I don’t understand where this share ends up and with what name.

I need some kind of “shared_from” and “path” to specify where this incoming share will end up, dont’t I?

, cause that’s what I do in the GUI; whenever I get an incoming share, I have to specify path to store it in.

I think I see the confusion.

In the GUI, when you “accept an incoming share” what you’re doing is adding a new share, with some of the values pre-filled from the incoming discovery data. If it’s an existing share, you just add the additional device to it. That’s all.

What matters across the network is the share id and the set of devices it’s shared with. You can create shares locally with the same id on multiple hosts, connect them together, and the folders will sync. If there were existing contents, they’ll get merged (or generate conflicts if the same filenames are in use). In current versions of syncthing, the GUI generates a random folder id by default, so this doesn’t happen unless you edit it to a user-chosen matching value.

The declarative version is the same, you choose all the values and syncthing runs with those settings: all the folders you declare are “accepted” already and will sync with any matching shares on the devices listed.