fix: simplify syncthing module
This commit is contained in:
@@ -8,7 +8,6 @@ with lib;
|
||||
|
||||
let
|
||||
cfg = config.my.syncthing;
|
||||
allDevices = import ./devices.nix;
|
||||
in
|
||||
{
|
||||
options.my.syncthing = {
|
||||
@@ -17,41 +16,11 @@ in
|
||||
type = types.str;
|
||||
default = "h";
|
||||
};
|
||||
deviceNames = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
};
|
||||
folders = mkOption {
|
||||
type = types.attrsOf (
|
||||
types.submodule {
|
||||
options = {
|
||||
path = mkOption { type = types.path; };
|
||||
id = mkOption { type = types.str; };
|
||||
devices = mkOption {
|
||||
type = types.listOf (
|
||||
types.either types.str (
|
||||
types.submodule {
|
||||
options = {
|
||||
device = mkOption { type = types.str; };
|
||||
type = mkOption {
|
||||
type = types.str;
|
||||
default = "sendreceive";
|
||||
};
|
||||
};
|
||||
}
|
||||
)
|
||||
);
|
||||
default = cfg.deviceNames;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
users.groups.${cfg.username} = { };
|
||||
users.users.${cfg.username}.extraGroups = [ cfg.username ];
|
||||
|
||||
services.syncthing = {
|
||||
enable = true;
|
||||
@@ -59,27 +28,6 @@ in
|
||||
group = cfg.username;
|
||||
configDir = "/home/${cfg.username}/.local/state/syncthing";
|
||||
openDefaultPorts = true;
|
||||
settings = {
|
||||
options = {
|
||||
localAnnounceEnabled = true;
|
||||
globalAnnounceEnabled = true;
|
||||
relaysEnabled = true;
|
||||
urAccepted = -1;
|
||||
};
|
||||
devices = mapAttrs (name: id: { inherit id; }) (
|
||||
filterAttrs (name: _: elem name cfg.deviceNames) allDevices
|
||||
);
|
||||
folders = mapAttrs (name: folder: {
|
||||
inherit (folder) id path;
|
||||
devices = map (
|
||||
device:
|
||||
if isString device then
|
||||
allDevices.${device}
|
||||
else
|
||||
device // { deviceID = allDevices.${device.device}; }
|
||||
) folder.devices;
|
||||
}) cfg.folders;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user