diff --git a/system/all/restic.nix b/system/all/restic.nix index 2f0d146..9ee866b 100644 --- a/system/all/restic.nix +++ b/system/all/restic.nix @@ -8,29 +8,46 @@ }; }; - config = { + config = let + servers = ["porani" "workhorse" "workout"]; + dirs = config.backup.all.restic.dirs; - backup.services.restic = - let - setup = server: { - passwordFile = toString ; - repo = "sftp::backup/remote-${config.networking.hostName}"; - requires = []; - extraArguments = [ - "sftp.command='ssh backup@${server} -i ${toString } -s sftp'" - ]; - initialize = true; - timerConfig = { - OnCalendar = "daily"; - Persistent = "true"; - }; - dirs = config.backup.all.restic.dirs; + setup = server: { + passwordFile = toString ; + repo = "sftp::backup/remote-${config.networking.hostName}"; + requires = []; + extraArguments = [ + "sftp.command='ssh backup@${server} -i ${toString } -s sftp'" + ]; + initialize = true; + timerConfig = { + OnCalendar = "daily"; + Persistent = "true"; }; - in - { - "on-porani" = setup "porani.private"; - "on-workhorse" = setup "workhorse.private"; - "on-workout" = setup "workout.private"; + dirs = dirs; + }; + + hostname = config.networking.hostName; + infoEntry = server: { + restic = { + folders = dirs; + from = hostname; + to = server; + }; + }; + + in { + + backup.services.restic = lib.zipAttrsWith + (name: vals: lib.head vals) + (map (server: { + "on-${server}" = setup "${server}.private"; + }) servers); + + environment.etc."info/restic-${hostname}.json" = { + enable = true; + text = builtins.toJSON (map infoEntry servers); }; }; + }