1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{
config,
lib,
...
}:
{
options.zpha.configure.syncthingBackup.enable = lib.mkEnableOption "";
config = lib.mkIf config.zpha.configure.syncthingBackup.enable (
let
shares = lib.removeAttrs config.services.syncthing.settings.folders [ "zaphyra-music" ];
in
{
sops.secrets = lib.pipe shares [
(lib.filterAttrs (name: value: value.enable))
(lib.mapAttrsToList (name: value: value.id))
(map (element: [
(lib.nameValuePair "restic/syncthing/${element}/repositoryPassword" { })
(lib.nameValuePair "restic/syncthing/${element}/sshPrivateKey" { })
]))
(lib.flatten)
(builtins.listToAttrs)
];
common.services.resticBackup = lib.pipe shares [
(lib.filterAttrs (name: value: value.enable))
(lib.mapAttrs' (
name: value:
lib.nameValuePair "syncthing-${name}" {
inherit (config.services.syncthing) user;
enable = true;
targets = [ "restic-target.fc9f.de" ];
sshKeyFile = config.sops.secrets."restic/syncthing/${name}/sshPrivateKey".path;
passwordFile = config.sops.secrets."restic/syncthing/${name}/repositoryPassword".path;
paths = [ value.path ];
exclude = [
".stfolder"
".stversions"
];
}
))
];
}
);
}