44 lines
1.2 KiB
Nix
44 lines
1.2 KiB
Nix
{
|
|
lib,
|
|
config,
|
|
...
|
|
} @ input: {
|
|
options = {
|
|
services.syncthing = {
|
|
configuration = (import ./configuration-type.nix) input;
|
|
deviceName = lib.mkOption {
|
|
type = lib.types.string;
|
|
};
|
|
};
|
|
};
|
|
|
|
config = {
|
|
services.syncthing.settings = {
|
|
devices =
|
|
lib.attrsets.mapAttrs (name: deviceConfig: {
|
|
id = deviceConfig.id;
|
|
})
|
|
config.services.syncthing.configuration.devices;
|
|
folders =
|
|
lib.attrsets.mapAttrs (folderName: folder: {
|
|
id = folder.folder.id;
|
|
label = folder.folder.label;
|
|
path = folder.path;
|
|
devices = lib.attrsets.mapAttrsToList (_: device: device.name) (
|
|
lib.attrsets.filterAttrs (
|
|
deviceName: device:
|
|
lib.lists.any
|
|
(
|
|
deviceFolder: deviceFolder.folder.id == folder.folder.id
|
|
) (
|
|
lib.attrsets.mapAttrsToList (_: deviceFolder: deviceFolder) device.folders
|
|
)
|
|
)
|
|
config.services.syncthing.configuration.devices
|
|
);
|
|
})
|
|
config.services.syncthing.configuration.devices.${config.services.syncthing.deviceName}.folders;
|
|
};
|
|
};
|
|
}
|