1
Fork 0
satellite/hosts/nixos/common/optional/services/restic/default.nix

76 lines
1.7 KiB
Nix
Raw Normal View History

2024-05-30 02:35:16 +02:00
{ config, lib, ... }:
let
backupUrl = lib.removeSuffix "\n" (builtins.readFile ./url.txt);
# {{{ Backup helper
2024-08-27 20:52:29 +02:00
createBackup =
{
name,
paths,
exclude,
pruneOpts,
}:
{
inherit pruneOpts paths;
2024-05-30 02:35:16 +02:00
2024-08-27 20:52:29 +02:00
initialize = true;
repository = "sftp:${backupUrl}:backups/${name}";
passwordFile = config.sops.secrets.backup_password.path;
extraOptions = [ "sftp.args='-i ${config.users.users.pilot.home}/.ssh/id_ed25519'" ];
2024-05-30 02:35:16 +02:00
2024-08-27 20:52:29 +02:00
exclude = [
# Syncthing / direnv / git / snapper stuff
".direnv"
".git"
".stfolder"
".stversions"
".snapshots"
] ++ exclude;
};
2024-05-30 02:35:16 +02:00
in
2024-08-27 20:52:29 +02:00
# }}}
2024-05-30 02:35:16 +02:00
{
sops.secrets.backup_password.sopsFile = ../../../secrets.yaml;
services.restic.backups = {
# {{{ Data
data = createBackup {
name = "data";
pruneOpts = [
"--keep-daily 7"
"--keep-weekly 4"
"--keep-monthly 12"
"--keep-yearly 0"
];
paths = [ "/persist/data" ];
exclude = [
# Projects are available on github and in my own forge already
"/persist/data${config.users.users.pilot.home}/projects"
];
};
# }}}
# {{{ State
state = createBackup {
name = "state";
pruneOpts = [
"--keep-daily 3"
"--keep-weekly 1"
"--keep-monthly 1"
"--keep-yearly 0"
];
paths = [ "/persist/state" ];
exclude =
2024-08-27 20:52:29 +02:00
let
home = "/persist/state/${config.users.users.pilot.home}";
2024-05-30 02:35:16 +02:00
in
[
"${home}/discord" # There's lots of cache stored in here
"${home}/steam" # Games can be quite big
];
};
# }}}
};
}