refactor syncthing module
This commit is contained in:
parent
b8ad65483f
commit
c11b582a6b
1 changed files with 19 additions and 20 deletions
|
|
@ -7,11 +7,17 @@ let
|
||||||
touchDevices = [ "iphone" "ipad" ];
|
touchDevices = [ "iphone" "ipad" ];
|
||||||
allDevices = pcDevices ++ touchDevices;
|
allDevices = pcDevices ++ touchDevices;
|
||||||
|
|
||||||
mkFolderOptions = name: { maxAgeDays ? 0 }: {
|
mkFolderOptions = name: overrides: let
|
||||||
enable = lib.mkEnableOption "${name} folder" // { default = true; };
|
opts = {
|
||||||
path = lib.mkOption { type = lib.types.str; default = "~/${name}"; };
|
enable = { type = lib.types.bool; default = true; };
|
||||||
maxAgeDays = lib.mkOption { type = lib.types.int; default = maxAgeDays; };
|
path = { type = lib.types.str; default = "~/${name}"; };
|
||||||
};
|
maxAgeDays = { type = lib.types.int; default = 0; };
|
||||||
|
devices = { type = lib.types.listOf lib.types.str; default = allDevices; };
|
||||||
|
};
|
||||||
|
in lib.mapAttrs (k: v: lib.mkOption {
|
||||||
|
type = v.type;
|
||||||
|
default = overrides.${k} or v.default;
|
||||||
|
}) opts;
|
||||||
|
|
||||||
mkVersioning = days:
|
mkVersioning = days:
|
||||||
if days == 0 then {}
|
if days == 0 then {}
|
||||||
|
|
@ -25,21 +31,13 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
mkFolder = name: folderCfg: extraAttrs:
|
|
||||||
lib.optionalAttrs folderCfg.enable {
|
|
||||||
${name} = {
|
|
||||||
path = folderCfg.path;
|
|
||||||
devices = extraAttrs.devices;
|
|
||||||
} // mkVersioning folderCfg.maxAgeDays;
|
|
||||||
};
|
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.syncthing-custom = {
|
options.syncthing-custom = {
|
||||||
folders = {
|
folders = {
|
||||||
Credentials = mkFolderOptions "Credentials" {};
|
Credentials = mkFolderOptions "Credentials" {};
|
||||||
Documents = mkFolderOptions "Documents" {};
|
Documents = mkFolderOptions "Documents" { devices = pcDevices; };
|
||||||
Media = mkFolderOptions "Media" {};
|
Media = mkFolderOptions "Media" { devices = lib.filter (d: d != "iphone") allDevices; };
|
||||||
Archive = mkFolderOptions "Archive" {};
|
Archive = mkFolderOptions "Archive" {};
|
||||||
};
|
};
|
||||||
enableGui = lib.mkOption {
|
enableGui = lib.mkOption {
|
||||||
|
|
@ -80,11 +78,12 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
folders =
|
folders = let
|
||||||
mkFolder "Credentials" cfg.folders.Credentials { devices = allDevices; }
|
enabled = lib.filterAttrs (_: f: f.enable) cfg.folders;
|
||||||
// mkFolder "Documents" cfg.folders.Documents { devices = pcDevices; }
|
in lib.mapAttrs (_: f: {
|
||||||
// mkFolder "Media" cfg.folders.Media { devices = lib.filter (d: d != "iphone") allDevices; }
|
path = f.path;
|
||||||
// mkFolder "Archive" cfg.folders.Archive { devices = allDevices; };
|
devices = f.devices;
|
||||||
|
} // mkVersioning f.maxAgeDays) enabled;
|
||||||
|
|
||||||
gui = {
|
gui = {
|
||||||
enabled = cfg.enableGui;
|
enabled = cfg.enableGui;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue