Skip to content

Commit 0bc8c16

Browse files
committed
syncthing: expose encryptionPassword
- Change `folder.devices` type into `oneOf [(listOf str) (attrsOf (submodule { ... }))]`. - Expose `encryptionPassord` within the attrSet of the devices option. This allows the user to set the encrpyption password use to share the folder's data with. We do this by file path, as opposed to string literal, because we do not want to embed the encrpyption password into the nix store.
1 parent b5e81d5 commit 0bc8c16

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

nixos/modules/services/networking/syncthing.nix

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,22 @@ let
3434
The options services.syncthing.settings.folders.<name>.{rescanInterval,watch,watchDelay}
3535
were removed. Please use, respectively, {rescanIntervalS,fsWatcherEnabled,fsWatcherDelayS} instead.
3636
'' {
37-
devices = map (device:
38-
if builtins.isString device then
39-
{ deviceId = cfg.settings.devices.${device}.id; }
37+
devices = let
38+
folderDevices = folder.devices;
39+
in
40+
if builtins.isList folderDevices then
41+
map (device:
42+
if builtins.isString device then
43+
{ deviceId = cfg.settings.devices.${device}.id; }
44+
else
45+
device
46+
) folderDevices
47+
else if builtins.isAttrs folderDevices then
48+
mapAttrsToList (deviceName: deviceValue:
49+
deviceValue // { deviceId = cfg.settings.devices.${deviceName}.id; }
50+
) folderDevices
4051
else
41-
device
42-
) folder.devices;
52+
throw "Invalid type for devices in folder '${folderName}'; expected list or attrset.";
4353
}) (filterAttrs (_: folder:
4454
folder.enable
4555
) cfg.settings.folders);
@@ -435,11 +445,30 @@ in {
435445
};
436446

437447
devices = mkOption {
438-
type = types.listOf types.str;
448+
type = types.oneOf [
449+
(types.listOf types.str)
450+
(types.attrsOf (types.submodule ({ name, ... }: {
451+
freeformType = settingsFormat.type;
452+
options = {
453+
encryptionPassword = mkOption {
454+
type = types.nullOr types.str;
455+
default = null;
456+
description = ''
457+
Path to encryption password. If set, the file will be read during
458+
service activation, without being embedded in derivation.
459+
'';
460+
};
461+
};
462+
}))
463+
)];
439464
default = [];
440465
description = ''
441466
The devices this folder should be shared with. Each device must
442467
be defined in the [devices](#opt-services.syncthing.settings.devices) option.
468+
469+
Either a list of strings, or an attribute set, where keys are defined in the
470+
[devices](#opt-services.syncthing.settings.devices) option, and values are
471+
device configurations.
443472
'';
444473
};
445474

0 commit comments

Comments
 (0)