nixos-config/modules/nixos/restic.nix

69 lines
1.8 KiB
Nix
Raw Normal View History

2024-09-14 08:41:22 +00:00
# TODO: https://github.com/lilyinstarlight/foosteros/blob/dfe1ab3eb68bfebfaa709482d52fa04ebdde81c8/config/restic.nix#L23 <- this is better
2024-08-25 09:45:58 +00:00
{
config,
2024-09-23 12:19:27 +00:00
pkgs,
2024-08-25 09:45:58 +00:00
lib,
...
}:
2023-12-01 14:22:43 +00:00
let
cfg = config.custom.restic;
in
{
options = {
custom.restic = {
2023-12-01 17:33:20 +00:00
enable = lib.mkEnableOption "restic";
2024-09-14 08:41:22 +00:00
paths = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [
"/home"
"/var/lib"
];
};
prune = lib.mkEnableOption "auto prune remote restic repo";
2023-12-01 14:22:43 +00:00
repositoryFile = lib.mkOption {
type = lib.types.str;
default = "";
};
2023-12-01 17:33:20 +00:00
passwordFile = lib.mkOption {
2023-12-01 14:22:43 +00:00
type = lib.types.str;
default = "";
};
};
};
2024-07-30 03:31:27 +00:00
config = lib.mkIf cfg.enable {
2024-09-14 08:41:22 +00:00
services.restic.backups.${config.networking.hostName} = lib.mkMerge [
{
2023-12-01 14:22:43 +00:00
repositoryFile = cfg.repositoryFile;
passwordFile = cfg.passwordFile;
exclude = [
"/home/*/.cache"
"/home/*/.cargo"
"/home/*/.local/share/Steam"
"/home/*/.local/share/flatpak"
];
timerConfig = {
OnCalendar = "00:05";
RandomizedDelaySec = "5h";
};
2024-09-14 08:41:22 +00:00
pruneOpts = lib.mkIf cfg.prune [
2023-12-01 14:22:43 +00:00
"--keep-daily 7"
"--keep-weekly 5"
"--keep-monthly 12"
"--keep-yearly 75"
];
2024-09-14 08:41:22 +00:00
paths = lib.mkDefault cfg.paths;
initialize = true;
}
(lib.mkIf (config.fileSystems."/".fsType == "btrfs") {
backupPrepareCommand = ''
2024-09-23 12:19:27 +00:00
${pkgs.btrfs-progs}/bin/btrfs subvolume snapshot -r / backup
2024-09-14 08:41:22 +00:00
'';
backupCleanupCommand = ''
2024-09-23 12:19:27 +00:00
${pkgs.btrfs-progs}/bin/btrfs subvolume delete /backup
2024-09-14 08:41:22 +00:00
'';
paths = map (p: "/backup" + p) cfg.paths;
})
];
2023-12-01 14:22:43 +00:00
};
}