expand syncthing folder options
This commit is contained in:
parent
4d8df7396a
commit
af53e9b502
3 changed files with 52 additions and 43 deletions
|
|
@ -7,4 +7,10 @@
|
||||||
../../../modules/media/tool.nix
|
../../../modules/media/tool.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
syncthing-custom.folders = {
|
||||||
|
Credentials.maxAgeDays = 30;
|
||||||
|
Documents.maxAgeDays = 30;
|
||||||
|
Media.maxAgeDays = 7;
|
||||||
|
Archive.maxAgeDays = 30;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,13 @@
|
||||||
../../../modules/schedule.nix
|
../../../modules/schedule.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
syncthing-custom.folders = {
|
||||||
|
Credentials.maxAgeDays = 30;
|
||||||
|
Documents.maxAgeDays = 30;
|
||||||
|
Media.maxAgeDays = 7;
|
||||||
|
Archive.maxAgeDays = 30;
|
||||||
|
};
|
||||||
|
|
||||||
services.scheduled-commands.dcim-consume = {
|
services.scheduled-commands.dcim-consume = {
|
||||||
enable = true;
|
enable = true;
|
||||||
description = "Move files in dcim consume folder to DCIM";
|
description = "Move files in dcim consume folder to DCIM";
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,45 @@
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.syncthing-custom;
|
cfg = config.syncthing-custom;
|
||||||
|
|
||||||
pcDevices = [ "macbook" "imac" "thinkpad" "nfss" ];
|
pcDevices = [ "macbook" "imac" "thinkpad" "nfss" ];
|
||||||
touchDevices = [ "iphone" "ipad" ];
|
touchDevices = [ "iphone" "ipad" ];
|
||||||
allDevices = pcDevices ++ touchDevices;
|
allDevices = pcDevices ++ touchDevices;
|
||||||
|
|
||||||
commonVersioning = {
|
mkFolderOptions = name: { maxAgeDays ? 0 }: {
|
||||||
type = "staggered";
|
enable = lib.mkEnableOption "${name} folder" // { default = true; };
|
||||||
params = {
|
path = lib.mkOption { type = lib.types.str; default = "~/${name}"; };
|
||||||
maxAge = "604800"; # 7 days
|
maxAgeDays = lib.mkOption { type = lib.types.int; default = maxAgeDays; };
|
||||||
cleanInterval = "3600"; # 1 hour
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mkVersioning = days:
|
||||||
|
if days == 0 then {}
|
||||||
|
else {
|
||||||
|
versioning = {
|
||||||
|
type = "staggered";
|
||||||
|
params = {
|
||||||
|
maxAge = toString (days * 86400);
|
||||||
|
cleanInterval = "3600";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
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 = {
|
||||||
enabledFolders = lib.mkOption {
|
folders = {
|
||||||
type = lib.types.listOf lib.types.str;
|
Credentials = mkFolderOptions "Credentials" {};
|
||||||
default = [ "Credentials" "Documents" "Archive" "Media" ];
|
Documents = mkFolderOptions "Documents" {};
|
||||||
description = "List of Syncthing folders to enable for this host.";
|
Media = mkFolderOptions "Media" {};
|
||||||
|
Archive = mkFolderOptions "Archive" {};
|
||||||
};
|
};
|
||||||
enableGui = lib.mkOption {
|
enableGui = lib.mkOption {
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
|
|
@ -36,9 +55,9 @@ in
|
||||||
tray.enable = false;
|
tray.enable = false;
|
||||||
overrideDevices = true;
|
overrideDevices = true;
|
||||||
overrideFolders = true;
|
overrideFolders = true;
|
||||||
|
|
||||||
guiAddress = lib.mkIf cfg.enableGui "127.0.0.1:8384";
|
guiAddress = lib.mkIf cfg.enableGui "127.0.0.1:8384";
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
devices = {
|
devices = {
|
||||||
"iphone" = {
|
"iphone" = {
|
||||||
|
|
@ -60,36 +79,13 @@ in
|
||||||
id = "S4QZW76-BOLIOW7-DVP326F-JIGW5DW-3PAD47L-OA456LB-2L6JZW7-YUGJRA6";
|
id = "S4QZW76-BOLIOW7-DVP326F-JIGW5DW-3PAD47L-OA456LB-2L6JZW7-YUGJRA6";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
folders =
|
folders =
|
||||||
(lib.optionalAttrs (lib.elem "Credentials" cfg.enabledFolders) {
|
mkFolder "Credentials" cfg.folders.Credentials { devices = allDevices; }
|
||||||
"Credentials" = {
|
// mkFolder "Documents" cfg.folders.Documents { devices = pcDevices; }
|
||||||
path = "~/Credentials";
|
// mkFolder "Media" cfg.folders.Media { devices = lib.filter (d: d != "iphone") allDevices; }
|
||||||
devices = allDevices;
|
// mkFolder "Archive" cfg.folders.Archive { devices = allDevices; };
|
||||||
versioning = commonVersioning;
|
|
||||||
};
|
|
||||||
})
|
|
||||||
// (lib.optionalAttrs (lib.elem "Documents" cfg.enabledFolders) {
|
|
||||||
"Documents" = {
|
|
||||||
path = "~/Documents";
|
|
||||||
devices = pcDevices;
|
|
||||||
versioning = commonVersioning;
|
|
||||||
};
|
|
||||||
})
|
|
||||||
// (lib.optionalAttrs (lib.elem "Media" cfg.enabledFolders) {
|
|
||||||
"Media" = {
|
|
||||||
path = "~/Media";
|
|
||||||
devices = lib.filter (d: d != "iphone") allDevices;
|
|
||||||
};
|
|
||||||
})
|
|
||||||
// (lib.optionalAttrs (lib.elem "Archive" cfg.enabledFolders) {
|
|
||||||
"Archive" = {
|
|
||||||
path = "~/Archive";
|
|
||||||
devices = allDevices;
|
|
||||||
versioning = commonVersioning;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
gui = {
|
gui = {
|
||||||
enabled = cfg.enableGui;
|
enabled = cfg.enableGui;
|
||||||
user = "yanlin";
|
user = "yanlin";
|
||||||
|
|
@ -97,7 +93,7 @@ in
|
||||||
useTLS = false;
|
useTLS = false;
|
||||||
insecureSkipHostcheck = true;
|
insecureSkipHostcheck = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
urAccepted = -1;
|
urAccepted = -1;
|
||||||
relaysEnabled = true;
|
relaysEnabled = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue