···
opt = options.services.syncthing;
defaultUser = "syncthing";
defaultGroup = defaultUser;
-
settingsFormat = pkgs.formats.json { };
-
devices = mapAttrsToList (_: device: device // {
-
}) cfg.settings.devices;
-
folders = mapAttrsToList (_: folder: folder //
-
throwIf (folder?rescanInterval || folder?watch || folder?watchDelay) ''
-
The options services.syncthing.settings.folders.<name>.{rescanInterval,watch,watchDelay}
-
were removed. Please use, respectively, {rescanIntervalS,fsWatcherEnabled,fsWatcherDelayS} instead.
-
if builtins.isString device then
-
{ deviceId = cfg.settings.devices.${device}.id; }
-
}) (filterAttrs (_: folder:
-
) cfg.settings.folders);
updateConfig = pkgs.writers.writeDash "merge-syncthing-config" ''
···
old_cfg=$(curl ${cfg.guiAddress}/rest/config)
# generate the new config by merging with the NixOS config options
-
new_cfg=$(printf '%s\n' "$old_cfg" | ${pkgs.jq}/bin/jq -c ${escapeShellArg ''. * ${builtins.toJSON cfg.settings} * {
-
"devices": (${builtins.toJSON devices}${optionalString (cfg.settings.devices == {} || ! cfg.overrideDevices) " + .devices"}),
-
"folders": (${builtins.toJSON folders}${optionalString (cfg.settings.folders == {} || ! cfg.overrideFolders) " + .folders"})
curl -X PUT -d "$new_cfg" ${cfg.guiAddress}/rest/config
···
Whether to delete the devices which are not configured via the
-
[devices](#opt-services.syncthing.settings.devices) option.
If set to `false`, devices added via the web
interface will persist and will have to be deleted manually.
overrideFolders = mkOption {
Whether to delete the folders which are not configured via the
-
[folders](#opt-services.syncthing.settings.folders) option.
If set to `false`, folders added via the web
interface will persist and will have to be deleted manually.
-
type = types.submodule {
-
freeformType = settingsFormat.type;
-
The options element contains all other global configuration options
-
type = types.submodule ({ name, ... }: {
-
freeformType = settingsFormat.type;
-
localAnnounceEnabled = mkOption {
-
description = lib.mdDoc ''
-
Whether to send announcements to the local LAN, also use such announcements to find other devices.
-
localAnnouncePort = mkOption {
-
description = lib.mdDoc ''
-
The port on which to listen and send IPv4 broadcast announcements to.
-
relaysEnabled = mkOption {
-
description = lib.mdDoc ''
-
When true, relays will be connected to and potentially used for device to device connections.
-
urAccepted = mkOption {
-
description = lib.mdDoc ''
-
Whether the user has accepted to submit anonymous usage data.
-
The default, 0, mean the user has not made a choice, and Syncthing will ask at some point in the future.
-
"-1" means no, a number above zero means that that version of usage reporting has been accepted.
-
limitBandwidthInLan = mkOption {
-
description = lib.mdDoc ''
-
Whether to apply bandwidth limits to devices in the same broadcast domain as the local device.
-
maxFolderConcurrency = mkOption {
-
description = lib.mdDoc ''
-
This option controls how many folders may concurrently be in I/O-intensive operations such as syncing or scanning.
-
The mechanism is described in detail in a [separate chapter](https://docs.syncthing.net/advanced/option-max-concurrency.html).
-
Peers/devices which Syncthing should communicate with.
-
Note that you can still add devices manually, but those changes
-
will be reverted on restart if [overrideDevices](#opt-services.syncthing.overrideDevices)
-
id = "7CFNTQM-IMTJBHJ-3UWRDIU-ZGQJFR6-VCXZ3NB-XUH3KZO-N52ITXR-LAIYUAU";
-
addresses = [ "tcp://192.168.0.10:51820" ];
-
type = types.attrsOf (types.submodule ({ name, ... }: {
-
freeformType = settingsFormat.type;
-
description = lib.mdDoc ''
-
The name of the device.
-
The device ID. See <https://docs.syncthing.net/dev/device-ids.html>.
-
autoAcceptFolders = mkOption {
-
Automatically create or share folders that this device advertises at the default path.
-
See <https://docs.syncthing.net/users/config.html?highlight=autoaccept#config-file-format>.
-
Folders which should be shared by Syncthing.
-
Note that you can still add folders manually, but those changes
-
will be reverted on restart if [overrideFolders](#opt-services.syncthing.overrideFolders)
example = literalExpression ''
-
devices = [ "bigbox" ];
-
type = types.attrsOf (types.submodule ({ name, ... }: {
-
freeformType = settingsFormat.type;
-
description = lib.mdDoc ''
-
Whether to share this folder.
-
This option is useful when you want to define all folders
-
in one place, but not every machine should share all folders.
-
# TODO for release 23.05: allow relative paths again and set
-
# working directory to cfg.dataDir
-
check = x: types.str.check x && (substring 0 1 x == "/" || substring 0 2 x == "~/");
-
description = types.str.description + " starting with / or ~/";
-
description = lib.mdDoc ''
-
The path to the folder which should be shared.
-
Only absolute paths (starting with `/`) and paths relative to
-
the [user](#opt-services.syncthing.user)'s home directory
-
(starting with `~/`) are allowed.
-
description = lib.mdDoc ''
-
The ID of the folder. Must be the same on all devices.
-
description = lib.mdDoc ''
-
The label of the folder.
-
type = types.listOf types.str;
-
The devices this folder should be shared with. Each device must
-
be defined in the [devices](#opt-services.syncthing.settings.devices) option.
-
versioning = mkOption {
-
How to keep changed/deleted files with Syncthing.
-
There are 4 different types of versioning with different parameters.
See <https://docs.syncthing.net/users/versioning.html>.
-
example = literalExpression ''
-
params.cleanoutDays = "1000";
-
fsPath = "/syncthing/backup";
-
cleanInterval = "3600";
-
params.versionsPath = pkgs.writers.writeBash "backup" '''
-
rm -rf "$folderpath/$filepath"
-
type = with types; nullOr (submodule {
-
freeformType = settingsFormat.type;
-
type = enum [ "external" "simple" "staggered" "trashcan" ];
-
The type of versioning.
-
See <https://docs.syncthing.net/users/versioning.html>.
-
copyOwnershipFromParent = mkOption {
-
On Unix systems, tries to copy file/folder ownership from the parent directory (the directory it’s located in).
-
Requires running Syncthing as a privileged user, or granting it additional capabilities (e.g. CAP_CHOWN on Linux).
Extra configuration options for Syncthing.
···
This option was removed because Syncthing now has the inotify functionality included under the name "fswatcher".
It can be enabled on a per-folder basis through the web interface.
-
(mkRenamedOptionModule [ "services" "syncthing" "extraOptions" ] [ "services" "syncthing" "settings" ])
-
(mkRenamedOptionModule [ "services" "syncthing" "folders" ] [ "services" "syncthing" "settings" "folders" ])
-
(mkRenamedOptionModule [ "services" "syncthing" "devices" ] [ "services" "syncthing" "settings" "devices" ])
-
(mkRenamedOptionModule [ "services" "syncthing" "options" ] [ "services" "syncthing" "settings" "options" ])
mkRenamedOptionModule [ "services" "syncthing" "declarative" o ] [ "services" "syncthing" o ]
) [ "cert" "key" "devices" "folders" "overrideDevices" "overrideFolders" "extraOptions"];
···
-
syncthing-init = mkIf (cfg.settings != {}) {
description = "Syncthing configuration updater";
requisite = [ "syncthing.service" ];
after = [ "syncthing.service" ];