···
opt = options.services.syncthing;
defaultUser = "syncthing";
defaultGroup = defaultUser;
10
-
settingsFormat = pkgs.formats.json { };
12
-
devices = mapAttrsToList (_: device: device // {
11
+
devices = mapAttrsToList (name: device: {
14
-
}) cfg.settings.devices;
13
+
inherit (device) name addresses introducer autoAcceptFolders;
16
-
folders = mapAttrsToList (_: folder: folder //
17
-
throwIf (folder?rescanInterval || folder?watch || folder?watchDelay) ''
18
-
The options services.syncthing.settings.folders.<name>.{rescanInterval,watch,watchDelay}
19
-
were removed. Please use, respectively, {rescanIntervalS,fsWatcherEnabled,fsWatcherDelayS} instead.
21
-
devices = map (device:
22
-
if builtins.isString device then
23
-
{ deviceId = cfg.settings.devices.${device}.id; }
27
-
}) (filterAttrs (_: folder:
16
+
folders = mapAttrsToList ( _: folder: {
17
+
inherit (folder) path id label type;
18
+
devices = map (device: { deviceId = cfg.devices.${device}.id; }) folder.devices;
19
+
rescanIntervalS = folder.rescanInterval;
20
+
fsWatcherEnabled = folder.watch;
21
+
fsWatcherDelayS = folder.watchDelay;
22
+
ignorePerms = folder.ignorePerms;
23
+
ignoreDelete = folder.ignoreDelete;
24
+
versioning = folder.versioning;
29
-
) 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
58
-
new_cfg=$(printf '%s\n' "$old_cfg" | ${pkgs.jq}/bin/jq -c ${escapeShellArg ''. * ${builtins.toJSON cfg.settings} * {
59
-
"devices": (${builtins.toJSON devices}${optionalString (cfg.settings.devices == {} || ! cfg.overrideDevices) " + .devices"}),
60
-
"folders": (${builtins.toJSON folders}${optionalString (cfg.settings.folders == {} || ! cfg.overrideFolders) " + .folders"})
57
+
new_cfg=$(printf '%s\n' "$old_cfg" | ${pkgs.jq}/bin/jq -c '. * {
58
+
"devices": (${builtins.toJSON devices}${optionalString (cfg.devices == {} || ! cfg.overrideDevices) " + .devices"}),
59
+
"folders": (${builtins.toJSON folders}${optionalString (cfg.folders == {} || ! cfg.overrideFolders) " + .folders"})
60
+
} * ${builtins.toJSON cfg.extraOptions}')
curl -X PUT -d "$new_cfg" ${cfg.guiAddress}/rest/config
···
Whether to delete the devices which are not configured via the
103
-
[devices](#opt-services.syncthing.settings.devices) option.
102
+
[devices](#opt-services.syncthing.devices) option.
If set to `false`, devices added via the web
interface will persist and will have to be deleted manually.
108
+
devices = mkOption {
110
+
description = mdDoc ''
111
+
Peers/devices which Syncthing should communicate with.
113
+
Note that you can still add devices manually, but those changes
114
+
will be reverted on restart if [overrideDevices](#opt-services.syncthing.overrideDevices)
119
+
id = "7CFNTQM-IMTJBHJ-3UWRDIU-ZGQJFR6-VCXZ3NB-XUH3KZO-N52ITXR-LAIYUAU";
120
+
addresses = [ "tcp://192.168.0.10:51820" ];
123
+
type = types.attrsOf (types.submodule ({ name, ... }: {
129
+
description = lib.mdDoc ''
130
+
The name of the device.
134
+
addresses = mkOption {
135
+
type = types.listOf types.str;
137
+
description = lib.mdDoc ''
138
+
The addresses used to connect to the device.
139
+
If this is left empty, dynamic configuration is attempted.
145
+
description = mdDoc ''
146
+
The device ID. See <https://docs.syncthing.net/dev/device-ids.html>.
150
+
introducer = mkOption {
153
+
description = mdDoc ''
154
+
Whether the device should act as an introducer and be allowed
155
+
to add folders on this computer.
156
+
See <https://docs.syncthing.net/users/introducer.html>.
160
+
autoAcceptFolders = mkOption {
163
+
description = mdDoc ''
164
+
Automatically create or share folders that this device advertises at the default path.
165
+
See <https://docs.syncthing.net/users/config.html?highlight=autoaccept#config-file-format>.
overrideFolders = mkOption {
Whether to delete the folders which are not configured via the
114
-
[folders](#opt-services.syncthing.settings.folders) option.
178
+
[folders](#opt-services.syncthing.folders) option.
If set to `false`, folders added via the web
interface will persist and will have to be deleted manually.
120
-
settings = mkOption {
121
-
type = types.submodule {
122
-
freeformType = settingsFormat.type;
125
-
options = mkOption {
127
-
description = mdDoc ''
128
-
The options element contains all other global configuration options
130
-
type = types.submodule ({ name, ... }: {
131
-
freeformType = settingsFormat.type;
133
-
localAnnounceEnabled = mkOption {
136
-
description = lib.mdDoc ''
137
-
Whether to send announcements to the local LAN, also use such announcements to find other devices.
184
+
folders = mkOption {
186
+
description = mdDoc ''
187
+
Folders which should be shared by Syncthing.
141
-
localAnnouncePort = mkOption {
144
-
description = lib.mdDoc ''
145
-
The port on which to listen and send IPv4 broadcast announcements to.
189
+
Note that you can still add folders manually, but those changes
190
+
will be reverted on restart if [overrideFolders](#opt-services.syncthing.overrideFolders)
193
+
example = literalExpression ''
195
+
"/home/user/sync" = {
197
+
devices = [ "bigbox" ];
201
+
type = types.attrsOf (types.submodule ({ name, ... }: {
149
-
relaysEnabled = mkOption {
152
-
description = lib.mdDoc ''
153
-
When true, relays will be connected to and potentially used for device to device connections.
204
+
enable = mkOption {
207
+
description = lib.mdDoc ''
208
+
Whether to share this folder.
209
+
This option is useful when you want to define all folders
210
+
in one place, but not every machine should share all folders.
157
-
urAccepted = mkOption {
160
-
description = lib.mdDoc ''
161
-
Whether the user has accepted to submit anonymous usage data.
162
-
The default, 0, mean the user has not made a choice, and Syncthing will ask at some point in the future.
163
-
"-1" means no, a number above zero means that that version of usage reporting has been accepted.
215
+
# TODO for release 23.05: allow relative paths again and set
216
+
# working directory to cfg.dataDir
217
+
type = types.str // {
218
+
check = x: types.str.check x && (substring 0 1 x == "/" || substring 0 2 x == "~/");
219
+
description = types.str.description + " starting with / or ~/";
222
+
description = lib.mdDoc ''
223
+
The path to the folder which should be shared.
224
+
Only absolute paths (starting with `/`) and paths relative to
225
+
the [user](#opt-services.syncthing.user)'s home directory
226
+
(starting with `~/`) are allowed.
167
-
limitBandwidthInLan = mkOption {
170
-
description = lib.mdDoc ''
171
-
Whether to apply bandwidth limits to devices in the same broadcast domain as the local device.
233
+
description = lib.mdDoc ''
234
+
The ID of the folder. Must be the same on all devices.
175
-
maxFolderConcurrency = mkOption {
178
-
description = lib.mdDoc ''
179
-
This option controls how many folders may concurrently be in I/O-intensive operations such as syncing or scanning.
180
-
The mechanism is described in detail in a [separate chapter](https://docs.syncthing.net/advanced/option-max-concurrency.html).
241
+
description = lib.mdDoc ''
242
+
The label of the folder.
247
+
type = types.listOf types.str;
191
-
Peers/devices which Syncthing should communicate with.
193
-
Note that you can still add devices manually, but those changes
194
-
will be reverted on restart if [overrideDevices](#opt-services.syncthing.overrideDevices)
250
+
The devices this folder should be shared with. Each device must
251
+
be defined in the [devices](#opt-services.syncthing.devices) option.
199
-
id = "7CFNTQM-IMTJBHJ-3UWRDIU-ZGQJFR6-VCXZ3NB-XUH3KZO-N52ITXR-LAIYUAU";
200
-
addresses = [ "tcp://192.168.0.10:51820" ];
203
-
type = types.attrsOf (types.submodule ({ name, ... }: {
204
-
freeformType = settingsFormat.type;
210
-
description = lib.mdDoc ''
211
-
The name of the device.
217
-
description = mdDoc ''
218
-
The device ID. See <https://docs.syncthing.net/dev/device-ids.html>.
222
-
autoAcceptFolders = mkOption {
225
-
description = mdDoc ''
226
-
Automatically create or share folders that this device advertises at the default path.
227
-
See <https://docs.syncthing.net/users/config.html?highlight=autoaccept#config-file-format>.
236
-
folders = mkOption {
255
+
versioning = mkOption {
239
-
Folders which should be shared by Syncthing.
241
-
Note that you can still add folders manually, but those changes
242
-
will be reverted on restart if [overrideFolders](#opt-services.syncthing.overrideFolders)
258
+
How to keep changed/deleted files with Syncthing.
259
+
There are 4 different types of versioning with different parameters.
260
+
See <https://docs.syncthing.net/users/versioning.html>.
example = literalExpression ''
247
-
"/home/user/sync" = {
249
-
devices = [ "bigbox" ];
267
+
params.keep = "10";
273
+
params.cleanoutDays = "1000";
278
+
type = "staggered";
279
+
fsPath = "/syncthing/backup";
281
+
cleanInterval = "3600";
282
+
maxAge = "31536000";
289
+
params.versionsPath = pkgs.writers.writeBash "backup" '''
292
+
rm -rf "$folderpath/$filepath"
253
-
type = types.attrsOf (types.submodule ({ name, ... }: {
254
-
freeformType = settingsFormat.type;
298
+
type = with types; nullOr (submodule {
257
-
enable = mkOption {
260
-
description = lib.mdDoc ''
261
-
Whether to share this folder.
262
-
This option is useful when you want to define all folders
263
-
in one place, but not every machine should share all folders.
268
-
# TODO for release 23.05: allow relative paths again and set
269
-
# working directory to cfg.dataDir
270
-
type = types.str // {
271
-
check = x: types.str.check x && (substring 0 1 x == "/" || substring 0 2 x == "~/");
272
-
description = types.str.description + " starting with / or ~/";
275
-
description = lib.mdDoc ''
276
-
The path to the folder which should be shared.
277
-
Only absolute paths (starting with `/`) and paths relative to
278
-
the [user](#opt-services.syncthing.user)'s home directory
279
-
(starting with `~/`) are allowed.
286
-
description = lib.mdDoc ''
287
-
The ID of the folder. Must be the same on all devices.
294
-
description = lib.mdDoc ''
295
-
The label of the folder.
299
-
devices = mkOption {
300
-
type = types.listOf types.str;
301
+
type = enum [ "external" "simple" "staggered" "trashcan" ];
303
-
The devices this folder should be shared with. Each device must
304
-
be defined in the [devices](#opt-services.syncthing.settings.devices) option.
303
+
The type of versioning.
304
+
See <https://docs.syncthing.net/users/versioning.html>.
308
-
versioning = mkOption {
307
+
fsPath = mkOption {
309
+
type = either str path;
311
-
How to keep changed/deleted files with Syncthing.
312
-
There are 4 different types of versioning with different parameters.
311
+
Path to the versioning folder.
See <https://docs.syncthing.net/users/versioning.html>.
315
-
example = literalExpression ''
320
-
params.keep = "10";
326
-
params.cleanoutDays = "1000";
331
-
type = "staggered";
332
-
fsPath = "/syncthing/backup";
334
-
cleanInterval = "3600";
335
-
maxAge = "31536000";
342
-
params.versionsPath = pkgs.writers.writeBash "backup" '''
345
-
rm -rf "$folderpath/$filepath"
351
-
type = with types; nullOr (submodule {
352
-
freeformType = settingsFormat.type;
355
-
type = enum [ "external" "simple" "staggered" "trashcan" ];
356
-
description = mdDoc ''
357
-
The type of versioning.
358
-
See <https://docs.syncthing.net/users/versioning.html>.
365
-
copyOwnershipFromParent = mkOption {
315
+
params = mkOption {
316
+
type = attrsOf (either str path);
369
-
On Unix systems, tries to copy file/folder ownership from the parent directory (the directory it’s located in).
370
-
Requires running Syncthing as a privileged user, or granting it additional capabilities (e.g. CAP_CHOWN on Linux).
318
+
The parameters for versioning. Structure depends on
319
+
[versioning.type](#opt-services.syncthing.folders._name_.versioning.type).
320
+
See <https://docs.syncthing.net/users/versioning.html>.
327
+
rescanInterval = mkOption {
330
+
description = lib.mdDoc ''
331
+
How often the folder should be rescanned for changes.
336
+
type = types.enum [ "sendreceive" "sendonly" "receiveonly" "receiveencrypted" ];
337
+
default = "sendreceive";
338
+
description = lib.mdDoc ''
339
+
Whether to only send changes for this folder, only receive them
340
+
or both. `receiveencrypted` can be used for untrusted devices. See
341
+
<https://docs.syncthing.net/users/untrusted.html> for reference.
348
+
description = lib.mdDoc ''
349
+
Whether the folder should be watched for changes by inotify.
353
+
watchDelay = mkOption {
356
+
description = lib.mdDoc ''
357
+
The delay after an inotify event is triggered.
361
+
ignorePerms = mkOption {
364
+
description = lib.mdDoc ''
365
+
Whether to ignore permission changes.
369
+
ignoreDelete = mkOption {
372
+
description = mdDoc ''
373
+
Whether to skip deleting files that are deleted by peers.
374
+
See <https://docs.syncthing.net/advanced/folder-ignoredelete.html>.
381
+
extraOptions = mkOption {
382
+
type = types.addCheck (pkgs.formats.json {}).type isAttrs;
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.
529
-
(mkRenamedOptionModule [ "services" "syncthing" "extraOptions" ] [ "services" "syncthing" "settings" ])
530
-
(mkRenamedOptionModule [ "services" "syncthing" "folders" ] [ "services" "syncthing" "settings" "folders" ])
531
-
(mkRenamedOptionModule [ "services" "syncthing" "devices" ] [ "services" "syncthing" "settings" "devices" ])
532
-
(mkRenamedOptionModule [ "services" "syncthing" "options" ] [ "services" "syncthing" "settings" "options" ])
mkRenamedOptionModule [ "services" "syncthing" "declarative" o ] [ "services" "syncthing" o ]
) [ "cert" "key" "devices" "folders" "overrideDevices" "overrideFolders" "extraOptions"];
···
618
-
syncthing-init = mkIf (cfg.settings != {}) {
618
+
syncthing-init = mkIf (
619
+
cfg.devices != {} || cfg.folders != {} || cfg.extraOptions != {}
description = "Syncthing configuration updater";
requisite = [ "syncthing.service" ];
after = [ "syncthing.service" ];