{ 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" ]; } )) ]; } ); }