System/modules/linux/services/borg.nix

46 lines
1.7 KiB
Nix
Raw Normal View History

2022-07-02 14:33:15 -04:00
{ config, lib, pkgs, ... }:
with lib; {
config = mkIf config.nathan.services.borg.enable {
# Add borg to the system packages
environment.systemPackages = with pkgs; [ borgbackup ];
2022-07-02 14:33:15 -04:00
services.borgbackup.jobs = {
rsyncnet = {
paths = [ "/home" "/var" "/etc" "/root" ]
++ config.nathan.services.borg.extraIncludes;
2022-07-02 14:33:15 -04:00
exclude = [
"*/.cache"
"*/.tmp"
"/home/${config.nathan.config.user}/Projects/*/target"
"/home/${config.nathan.config.user}/Work/*/target"
"/home/${config.nathan.config.user}/.local/share/Steam"
"/home/${config.nathan.config.user}/*/Cache"
"/home/*/Downloads"
"/var/dislocker"
2022-09-27 00:25:38 -04:00
"/var/cache"
] ++ config.nathan.services.borg.extraExcludes;
repo =
"${config.nathan.services.borg.location}/${config.networking.hostName}";
2022-07-02 14:33:15 -04:00
encryption = {
mode = "repokey-blake2";
passCommand = "cat ${config.nathan.services.borg.passwordFile}";
};
environment.BORG_RSH = "ssh -i ${config.nathan.services.borg.sshKey}";
compression = "auto,zstd";
startAt = config.nathan.services.borg.startAt;
prune.keep = if config.nathan.services.borg.keepForever then {
2022-07-02 14:33:15 -04:00
within = "7d"; # Keep all archives for the past week
daily = 1; # Keep 1 snapshot a day for 2 weeks
weekly = 4; # Keep 1 snapshot a week for 4 weeks
monthly = -1; # Keep unlimited monthly backups
} else {
within = "7d"; # Keep all archives for the past week
daily = 1; # Keep 1 snapshot a day for 2 weeks
weekly = 4; # Keep 1 snapshot a week for 4 weeks
monthly = 3; # Keep 3 monthly backups
2022-07-02 14:33:15 -04:00
};
};
};
};
}