nixos-config/system/all/restic.nix

58 lines
1.3 KiB
Nix
Raw Normal View History

2019-10-24 02:20:38 +02:00
{ config, lib, ... }:
{
options = {
backup.all.restic.dirs = lib.mkOption {
default = [];
type = with lib.types; listOf str;
};
};
2019-10-28 18:33:40 +01:00
config = let
servers = ["porani" "workhorse" "workout"];
dirs = config.backup.all.restic.dirs;
setup = server: {
passwordFile = toString <secrets/backup/restic-repo>;
repo = "sftp::backup/remote-${config.networking.hostName}";
requires = [];
extraArguments = [
"sftp.command='ssh backup@${server} -i ${toString <secrets/backup/sftp-user_rsa>} -s sftp'"
];
initialize = true;
timerConfig = {
OnCalendar = "daily";
Persistent = "true";
2019-10-24 02:20:38 +02:00
};
2019-10-28 18:33:40 +01:00
dirs = dirs;
};
hostname = config.networking.hostName;
infoEntry = server: {
restic = {
folders = dirs;
from = hostname;
2019-10-28 19:01:17 +01:00
to = {
server = server;
repo = config.backup.services.restic."on-${server}".repo;
};
enable = config.backup.services.restic."on-${server}".enable;
2019-10-28 18:33:40 +01:00
};
};
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);
2019-10-24 02:20:38 +02:00
};
};
2019-10-28 18:33:40 +01:00
2019-10-24 02:20:38 +02:00
}