Syncthing: Difference between revisions

Onny (talk | contribs)
Cleanup
Onny (talk | contribs)
Cleanup
Line 17: Line 17:


== Configuration ==
== Configuration ==
Follow the official ''[https://docs.syncthing.net/intro/getting-started.html Getting Started]'' guide to get started.


Note: using a declarative configuration will overwrite files in <code>configDir</code>.
=== Sync folders and trusted remote hosts ===
 
Following configuration will trust the remote hosts <code>device1</code> and <code>device2</code> by adding their <code>id</code>s. The shares <code>Documents</code> and <code>Example</code> are added to the local node, defined by their local file paths and list of allowed devices.<syntaxhighlight lang="nix">
Note: every available option can be sourced from here https://mynixos.com/nixpkgs/options/services.syncthing
services.syncthing = {
 
   settings = {
You can declaratively set your Syncthing folders by using the <code>services.syncthing.devices</code> and <code>services.syncthing.folders</code> options:
     devices = {
 
       "device1" = { id = "DEVICE-ID-GOES-HERE"; };
<syntaxhighlight lang="nix">
      "device2" = { id = "DEVICE-ID-GOES-HERE"; };
services = {
    };
   syncthing = {
    folders = {
     enable = true;
      "Documents" = {
    user = "myusername";
        path = "/home/myusername/Documents";
    dataDir = "/home/myusername/Documents";
        devices = [ "device1" "device2" ];
    configDir = "/home/myusername/Documents/.config/syncthing";
    overrideDevices = true;    # overrides any devices added or deleted through the WebUI
    overrideFolders = true;    # overrides any folders added or deleted through the WebUI
    settings = {
       devices = {
        "device1" = { id = "DEVICE-ID-GOES-HERE"; };
        "device2" = { id = "DEVICE-ID-GOES-HERE"; };
       };
       };
       folders = {
       "Example" = {
        "Documents" = {         # Folder ID in Syncthing, also the name of folder (label) by default
         path = "/home/myusername/Example";
          path = "/home/myusername/Documents";    # Which folder to add to Syncthing
        devices = [ "device1" ];
          devices = [ "device1" "device2" ];      # Which devices to share the folder with
        # By default, Syncthing doesn't sync file permissions. This line enables it for this folder.
        };
         ignorePerms = false;
         "Example" = {
          label = "Private";                      # Optional label for the folder
          path = "/home/myusername/Example";
          devices = [ "device1" ];
          ignorePerms = false;  # By default, Syncthing doesn't sync file permissions. This line enables it for this folder.
         };
       };
       };
     };
     };
   };
   };
};
};
</syntaxhighlight>Beware when adding additional settings via <code>services.syncthing.settings</code>, because sometimes you cannot use the key as in the documentation. For example, when setting the ''Sync Protocol Listen Address'': The key in the [https://docs.syncthing.net/users/config.html#config-file-format documentation] is <code>listenAddress</code>, however, because the value is a list the key used in <code>services.syncthing.settings</code> has to be <code>listenAddresses</code> (notice the extra <code>es</code>). See the following example:<syntaxhighlight lang="nix">
settings = {
  options = {
    listenAddresses = [ # listenAddress in the syncthing documentation
      "relay://replay-server/?id=<device-id>"
    ];
    globalAnnounceServers = [ # globalAnnounceServer in the syncthing documentation
      "https://relay-server/?id=<device-id>"
    ];
  };
};
</syntaxhighlight>
</syntaxhighlight>
=== Declarative node IDs ===
=== Declarative node IDs ===
If you set up Syncthing with the above configuration, you will still need to manually accept the connection from your other devices. If you want to make this automatic, you must also set the key.pem and cert.pem options:
If you set up Syncthing with the above configuration, you will still need to manually accept the connection from your other devices. If you want to make this automatic, you must also set the key.pem and cert.pem options:
Line 89: Line 62:
cert.pem  config.xml  key.pem</syntaxhighlight>
cert.pem  config.xml  key.pem</syntaxhighlight>


== Disable default sync folder ==
== Tips and tricks ==
 
=== Disable default sync folder ===
Syncthing creates a 'Sync' folder in your home directory every time it regenerates a configuration, even if your declarative configuration does not have this folder. You can disable that by setting the STNODEFAULTFOLDER environment variable:
Syncthing creates a 'Sync' folder in your home directory every time it regenerates a configuration, even if your declarative configuration does not have this folder. You can disable that by setting the STNODEFAULTFOLDER environment variable:
<syntaxhighlight lang="nix">systemd.services.syncthing.environment.STNODEFAULTFOLDER = "true"; # Don't create default ~/Sync folder</syntaxhighlight>
<syntaxhighlight lang="nix">systemd.services.syncthing.environment.STNODEFAULTFOLDER = "true"; # Don't create default ~/Sync folder</syntaxhighlight>


== Home-manager service ==
== See also ==


https://github.com/nix-community/home-manager/blob/master/modules/services/syncthing.nix
* Home-Manager service https://github.com/nix-community/home-manager/blob/master/modules/services/syncthing.nix
[[Category: Applications]]
[[Category: Applications]]