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

96 lines
2.2 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 /persist/state/etc/ssh/ssh_host_ed25519_key'" ];
2024-05-30 02:35:16 +02:00
2024-08-27 20:52:29 +02:00
exclude = [
".direnv" # Direnv
".git" # Git
".stfolder" # Syncthing
".stversions" # Syncthing
".snapshots" # Snapper
2024-08-27 20:52:29 +02:00
] ++ 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";
# Kept for at most 1 year
2024-05-30 02:35:16 +02:00
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"
# Screenshots are usually worthless
"/persist/data${config.users.users.pilot.home}/media/pictures/screenshots"
2024-05-30 02:35:16 +02:00
];
};
# }}}
# {{{ State
state = createBackup {
name = "state";
# Kept for at most 1 month
2024-05-30 02:35:16 +02:00
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
[
"/persist/state/var/log"
"${home}/discord"
"${home}/element"
"${home}/firefox"
"${home}/lutris"
"${home}/qmk"
"${home}/signal"
"${home}/spotify"
"${home}/steam"
"${home}/whatsapp"
"${home}/wine"
2024-05-30 02:35:16 +02:00
];
};
# }}}
};
environment.persistence."/persist/local/cache".directories = [
"/var/cache/restic-backups-data"
"/var/cache/restic-backups-state"
];
2024-05-30 02:35:16 +02:00
}