···
cfg = config.services.syncthing;
defaultUser = "syncthing";
8
+
defaultGroup = defaultUser;
devices = mapAttrsToList (name: device: {
inherit (device) name addresses introducer;
12
-
}) cfg.declarative.devices;
folders = mapAttrsToList ( _: folder: {
inherit (folder) path id label type;
16
-
devices = map (device: { deviceId = cfg.declarative.devices.${device}.id; }) folder.devices;
17
+
devices = map (device: { deviceId = cfg.devices.${device}.id; }) folder.devices;
rescanIntervalS = folder.rescanInterval;
fsWatcherEnabled = folder.watch;
fsWatcherDelayS = folder.watchDelay;
···
26
-
) cfg.declarative.folders);
updateConfig = pkgs.writers.writeDash "merge-syncthing-config" ''
···
# generate the new config by merging with the NixOS config options
new_cfg=$(echo "$old_cfg" | ${pkgs.jq}/bin/jq -c '. * {
53
-
"devices": (${builtins.toJSON devices}${optionalString (! cfg.declarative.overrideDevices) " + .devices"}),
54
-
"folders": (${builtins.toJSON folders}${optionalString (! cfg.declarative.overrideFolders) " + .folders"})
55
-
} * ${builtins.toJSON cfg.declarative.extraOptions}')
54
+
"devices": (${builtins.toJSON devices}${optionalString (! cfg.overrideDevices) " + .devices"}),
55
+
"folders": (${builtins.toJSON folders}${optionalString (! cfg.overrideFolders) " + .folders"})
56
+
} * ${builtins.toJSON cfg.extraOptions}')
curl -X PUT -d "$new_cfg" ${cfg.guiAddress}/rest/config
···
71
-
enable = mkEnableOption ''
72
-
Syncthing - the self-hosted open-source alternative
73
-
to Dropbox and Bittorrent Sync. Initial interface will be
74
-
available on http://127.0.0.1:8384/.
72
+
enable = mkEnableOption
73
+
"Syncthing, a self-hosted open-source alternative to Dropbox and Bittorrent Sync";
79
-
type = types.nullOr types.str;
82
-
Path to users cert.pem file, will be copied into Syncthing's
83
-
<literal>configDir</literal>
76
+
type = types.nullOr types.str;
79
+
Path to the <literal>cert.pem</literal> file, which will be copied into Syncthing's
80
+
<link linkend="opt-services.syncthing.configDir">configDir</link>.
88
-
type = types.nullOr types.str;
91
-
Path to users key.pem file, will be copied into Syncthing's
92
-
<literal>configDir</literal>
85
+
type = types.nullOr types.str;
88
+
Path to the <literal>key.pem</literal> file, which will be copied into Syncthing's
89
+
<link linkend="opt-services.syncthing.configDir">configDir</link>.
93
+
overrideDevices = mkOption {
97
+
Whether to delete the devices which are not configured via the
98
+
<link linkend="opt-services.syncthing.devices">devices</link> option.
99
+
If set to <literal>false</literal>, devices added via the web
100
+
interface will persist and will have to be deleted manually.
104
+
devices = mkOption {
107
+
Peers/devices which Syncthing should communicate with.
96
-
overrideDevices = mkOption {
100
-
Whether to delete the devices which are not configured via the
101
-
<literal>declarative.devices</literal> option.
102
-
If set to false, devices added via the webinterface will
103
-
persist but will have to be deleted manually.
109
+
Note that you can still add devices manually, but those changes
110
+
will be reverted on restart if <link linkend="opt-services.syncthing.overrideDevices">overrideDevices</link>
115
+
id = "7CFNTQM-IMTJBHJ-3UWRDIU-ZGQJFR6-VCXZ3NB-XUH3KZO-N52ITXR-LAIYUAU";
116
+
addresses = [ "tcp://192.168.0.10:51820" ];
119
+
type = types.attrsOf (types.submodule ({ name, ... }: {
107
-
devices = mkOption {
110
-
Peers/devices which Syncthing should communicate with.
114
-
id = "7CFNTQM-IMTJBHJ-3UWRDIU-ZGQJFR6-VCXZ3NB-XUH3KZO-N52ITXR-LAIYUAU";
115
-
addresses = [ "tcp://192.168.0.10:51820" ];
126
+
The name of the device.
118
-
type = types.attrsOf (types.submodule ({ name, ... }: {
130
+
addresses = mkOption {
131
+
type = types.listOf types.str;
134
+
The addresses used to connect to the device.
135
+
If this is left empty, dynamic configuration is attempted.
129
-
addresses = mkOption {
130
-
type = types.listOf types.str;
133
-
The addresses used to connect to the device.
134
-
If this is let empty, dynamic configuration is attempted
142
+
The device ID. See <link xlink:href="https://docs.syncthing.net/dev/device-ids.html"/>.
141
-
The id of the other peer, this is mandatory. It's documented at
142
-
https://docs.syncthing.net/dev/device-ids.html
146
+
introducer = mkOption {
150
+
Whether the device should act as an introducer and be allowed
151
+
to add folders on this computer.
152
+
See <link xlink:href="https://docs.syncthing.net/users/introducer.html"/>.
146
-
introducer = mkOption {
150
-
If the device should act as an introducer and be allowed
151
-
to add folders on this computer.
160
+
overrideFolders = mkOption {
164
+
Whether to delete the folders which are not configured via the
165
+
<link linkend="opt-services.syncthing.folders">folders</link> option.
166
+
If set to <literal>false</literal>, folders added via the web
167
+
interface will persist and will have to be deleted manually.
159
-
overrideFolders = mkOption {
163
-
Whether to delete the folders which are not configured via the
164
-
<literal>declarative.folders</literal> option.
165
-
If set to false, folders added via the webinterface will persist
166
-
but will have to be deleted manually.
171
+
folders = mkOption {
174
+
Folders which should be shared by Syncthing.
170
-
folders = mkOption {
173
-
Folders which should be shared by Syncthing.
175
-
example = literalExample ''
177
-
"/home/user/sync" = {
179
-
devices = [ "bigbox" ];
183
-
type = types.attrsOf (types.submodule ({ name, ... }: {
176
+
Note that you can still add devices manually, but those changes
177
+
will be reverted on restart if <link linkend="opt-services.syncthing.overrideDevices">overrideDevices</link>
180
+
example = literalExample ''
182
+
"/home/user/sync" = {
184
+
devices = [ "bigbox" ];
188
+
type = types.attrsOf (types.submodule ({ name, ... }: {
186
-
enable = mkOption {
191
-
This option is useful when you want to define all folders
192
-
in one place, but not every machine should share all folders.
191
+
enable = mkOption {
195
+
Whether to share this folder.
196
+
This option is useful when you want to define all folders
197
+
in one place, but not every machine should share all folders.
200
-
The path to the folder which should be shared.
205
+
The path to the folder which should be shared.
208
-
The id of the folder. Must be the same on all devices.
213
+
The ID of the folder. Must be the same on all devices.
216
-
The label of the folder.
221
+
The label of the folder.
220
-
devices = mkOption {
221
-
type = types.listOf types.str;
224
-
The devices this folder should be shared with. Must be defined
225
-
in the <literal>declarative.devices</literal> attribute.
225
+
devices = mkOption {
226
+
type = types.listOf types.str;
229
+
The devices this folder should be shared with. Each device must
230
+
be defined in the <link linkend="opt-services.syncthing.devices">devices</link> option.
229
-
versioning = mkOption {
232
-
How to keep changed/deleted files with Syncthing.
233
-
There are 4 different types of versioning with different parameters.
234
-
See https://docs.syncthing.net/users/versioning.html
234
+
versioning = mkOption {
237
+
How to keep changed/deleted files with Syncthing.
238
+
There are 4 different types of versioning with different parameters.
239
+
See <link xlink:href="https://docs.syncthing.net/users/versioning.html"/>.
241
+
example = literalExample ''
···
262
-
params.versionsPath = pkgs.writers.writeBash "backup" ''
268
+
params.versionsPath = pkgs.writers.writeBash "backup" '''
rm -rf "$folderpath/$filepath"
270
-
type = with types; nullOr (submodule {
273
-
type = enum [ "external" "simple" "staggered" "trashcan" ];
275
-
Type of versioning.
276
-
See https://docs.syncthing.net/users/versioning.html
279
-
params = mkOption {
280
-
type = attrsOf (either str path);
282
-
Parameters for versioning. Structure depends on versioning.type.
283
-
See https://docs.syncthing.net/users/versioning.html
277
+
type = with types; nullOr (submodule {
280
+
type = enum [ "external" "simple" "staggered" "trashcan" ];
282
+
The type of versioning.
283
+
See <link xlink:href="https://docs.syncthing.net/users/versioning.html"/>.
290
-
rescanInterval = mkOption {
294
-
How often the folders should be rescaned for changes.
286
+
params = mkOption {
287
+
type = attrsOf (either str path);
289
+
The parameters for versioning. Structure depends on
290
+
<link linkend="opt-services.syncthing.folders._name_.versioning.type">versioning.type</link>.
291
+
See <link xlink:href="https://docs.syncthing.net/users/versioning.html"/>.
299
-
type = types.enum [ "sendreceive" "sendonly" "receiveonly" ];
300
-
default = "sendreceive";
302
-
Whether to send only changes from this folder, only receive them
298
+
rescanInterval = mkOption {
302
+
How often the folder should be rescanned for changes.
311
-
Whether the folder should be watched for changes by inotify.
307
+
type = types.enum [ "sendreceive" "sendonly" "receiveonly" ];
308
+
default = "sendreceive";
310
+
Whether to only send changes for this folder, only receive them
315
-
watchDelay = mkOption {
319
-
The delay after an inotify event is triggered.
319
+
Whether the folder should be watched for changes by inotify.
323
-
ignorePerms = mkOption {
327
-
Whether to propagate permission changes.
323
+
watchDelay = mkOption {
327
+
The delay after an inotify event is triggered.
331
-
ignoreDelete = mkOption {
335
-
Whether to delete files in destination. See <link
336
-
xlink:href="https://docs.syncthing.net/advanced/folder-ignoredelete.html">
337
-
upstream's docs</link>.
331
+
ignorePerms = mkOption {
335
+
Whether to ignore permission changes.
344
-
extraOptions = mkOption {
345
-
type = types.addCheck (pkgs.formats.json {}).type isAttrs;
348
-
Extra configuration options for Syncthing.
351
-
options.localAnnounceEnabled = false;
352
-
gui.theme = "black";
339
+
ignoreDelete = mkOption {
343
+
Whether to skip deleting files that are deleted by peers.
344
+
See <link xlink:href="https://docs.syncthing.net/advanced/folder-ignoredelete.html"/>.
351
+
extraOptions = mkOption {
352
+
type = types.addCheck (pkgs.formats.json {}).type isAttrs;
355
+
Extra configuration options for Syncthing.
356
+
See <link xlink:href="https://docs.syncthing.net/users/config.html"/>.
359
+
options.localAnnounceEnabled = false;
360
+
gui.theme = "black";
···
default = "127.0.0.1:8384";
361
-
Address to serve the GUI.
368
+
The address to serve the web interface at.
systemService = mkOption {
368
-
description = "Auto launch Syncthing as a system service.";
376
+
Whether to auto-launch Syncthing as a system service.
383
+
example = "yourUser";
375
-
Syncthing will be run under this user (user will be created if it doesn't exist.
376
-
This can be your user name).
385
+
The user to run Syncthing as.
386
+
By default, a user named <literal>${defaultUser}</literal> will be created.
382
-
default = defaultUser;
392
+
default = defaultGroup;
393
+
example = "yourGroup";
384
-
Syncthing will be run under this group (group will not be created if it doesn't exist.
385
-
This can be your user name).
395
+
The group to run Syncthing under.
396
+
By default, a group named <literal>${defaultGroup}</literal> will be created.
···
example = "socks5://address.com:1234";
394
-
Overwrites all_proxy environment variable for the Syncthing process to
395
-
the given value. This is normaly used to let relay client connect
396
-
through SOCKS5 proxy server.
405
+
Overwrites the all_proxy environment variable for the Syncthing process to
406
+
the given value. This is normally used to let Syncthing connect
407
+
through a SOCKS5 proxy server.
408
+
See <link xlink:href="https://docs.syncthing.net/users/proxying.html"/>.
default = "/var/lib/syncthing";
415
+
example = "/home/yourUser";
404
-
Path where synced directories will exist.
417
+
The path where synchronised directories will exist.
408
-
configDir = mkOption {
422
+
cond = versionAtLeast config.system.stateVersion "19.03";
411
-
Path where the settings and keys will exist.
426
+
The path where the settings and keys will exist.
415
-
nixos = config.system.stateVersion;
416
-
cond = versionAtLeast nixos "19.03";
417
-
in cfg.dataDir + (optionalString cond "/.config/syncthing");
428
+
default = cfg.dataDir + (optionalString cond "/.config/syncthing");
429
+
defaultText = literalExample "dataDir${optionalString cond " + \"/.config/syncthing\""}";
openDefaultPorts = mkOption {
423
-
example = literalExample "true";
425
-
Open the default ports in the firewall:
426
-
- TCP 22000 for transfers
427
-
- UDP 21027 for discovery
428
-
If multiple users are running Syncthing on this machine, you will need to manually open a set of ports for each instance and leave this disabled.
429
-
Alternatively, if are running only a single instance on this machine using the default ports, enable this.
437
+
Whether to open the default ports in the firewall: TCP 22000 for transfers
438
+
and UDP 21027 for discovery.
440
+
If multiple users are running Syncthing on this machine, you will need
441
+
to manually open a set of ports for each instance and leave this disabled.
442
+
Alternatively, if you are running only a single instance on this machine
443
+
using the default ports, enable this.
default = pkgs.syncthing;
436
-
defaultText = "pkgs.syncthing";
437
-
example = literalExample "pkgs.syncthing";
450
+
defaultText = literalExample "pkgs.syncthing";
439
-
Syncthing package to use.
452
+
The Syncthing package to use.
446
-
(mkRemovedOptionModule ["services" "syncthing" "useInotify"] ''
459
+
(mkRemovedOptionModule [ "services" "syncthing" "useInotify" ] ''
This option was removed because Syncthing now has the inotify functionality included under the name "fswatcher".
448
-
It can be enabled on a per-folder basis through the webinterface.
461
+
It can be enabled on a per-folder basis through the web interface.
464
+
mkRenamedOptionModule [ "services" "syncthing" "declarative" o ] [ "services" "syncthing" o ]
465
+
) [ "cert" "key" "devices" "folders" "overrideDevices" "overrideFolders" "extraOptions"];
···
473
-
users.groups = mkIf (cfg.systemService && cfg.group == defaultUser) {
474
-
${defaultUser}.gid =
488
+
users.groups = mkIf (cfg.systemService && cfg.group == defaultGroup) {
489
+
${defaultGroup}.gid =
config.ids.gids.syncthing;
···
RestartForceExitStatus="3 4";
494
-
ExecStartPre = mkIf (cfg.declarative.cert != null || cfg.declarative.key != null)
509
+
ExecStartPre = mkIf (cfg.cert != null || cfg.key != null)
"+${pkgs.writers.writeBash "syncthing-copy-keys" ''
install -dm700 -o ${cfg.user} -g ${cfg.group} ${cfg.configDir}
497
-
${optionalString (cfg.declarative.cert != null) ''
498
-
install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.declarative.cert} ${cfg.configDir}/cert.pem
512
+
${optionalString (cfg.cert != null) ''
513
+
install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.cert} ${cfg.configDir}/cert.pem
500
-
${optionalString (cfg.declarative.key != null) ''
501
-
install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.declarative.key} ${cfg.configDir}/key.pem
515
+
${optionalString (cfg.key != null) ''
516
+
install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.key} ${cfg.configDir}/key.pem
···
532
-
cfg.declarative.devices != {} || cfg.declarative.folders != {} || cfg.declarative.extraOptions != {}
547
+
cfg.devices != {} || cfg.folders != {} || cfg.extraOptions != {}
description = "Syncthing configuration updater";
after = [ "syncthing.service" ];