Files
nix-config/modules/services/borgmatic.nix
Weckyy702 f6585da4b7 borgmatic: Rework borgmatic config to be a little less silly
Instead of globally excluding by pattern, exclude directories that
contain a .borgignore file

This makes the borg config more scalable across different setups
2026-04-02 13:48:08 +02:00

73 lines
1.9 KiB
Nix

{
flake.modules.homeManager.borgmatic =
{ config
, osConfig
, pkgs
, lib
, ...
}:
let
hostname = osConfig.networking.hostName;
username = config.home.username;
in
{
home.packages = with pkgs; [
libnotify
borgmatic
];
programs.borgmatic = {
enable = true;
backups.default = {
location = {
repositories = [
{
label = "duke";
path = "ssh://borg@duke.veltnet:2222/home/borg/backups/${hostname}-${username}";
}
];
excludeHomeManagerSymlinks = true;
patterns = [
#TODO: home.homeDirectory might be usable here
#TODO: should be user and machine specific
"R /home/${username}"
"+ /home/${username}/.ssh"
"- /home/${username}/.*"
"- **/node_modules"
"- **/.cache"
"- **/*build"
"- **/target"
"- **/.venv"
"- **/venv"
"- **/.gradle"
"- **/out"
"- **/dist"
"- **/.pio"
];
extraConfig.exclude_if_present = [ ".borgignore" ];
};
retention.keepWeekly = 2;
storage.extraConfig.ssh_command = "ssh -i /home/${username}/.ssh/id_ed25519_borg";
#FIXME: consistency checks!!!
};
};
#TODO: there is a services.borgmatic
systemd.user.services.borgmatic = {
Unit.Description = "Create a backup using borgmatic";
Service.ExecStart = "${pkgs.borgmatic}/bin/borgmatic create --stats";
};
systemd.user.timers.borgmatic = {
Unit.Description = "Create weekly backups using borgmatic";
Timer = {
OnCalendar = "Weekly";
Persistent = true;
};
Install.WantedBy = [ "timers.target" ];
};
};
}