dotfiles.nix/home/services/tarsnap.nix

51 lines
1.3 KiB
Nix
Raw Normal View History

2024-07-18 14:16:04 +00:00
{
config,
pkgs,
lib,
...
}:
{
# set configuration in ~ so tarsnap cli works interactively
home.file.".tarsnaprc".text = ''
cachedir ${config.xdg.cacheHome}
keyfile ${config.xdg.configHome}/tarsnap/read-write-delete.key
nodump
print-stats
checkpoint-bytes 1G
humanize-numbers
'';
2022-10-10 21:54:15 +00:00
# tarsnap periodic backup configuration
2024-07-18 14:16:04 +00:00
launchd.agents.tarsnap =
let
logPath = "${config.xdg.stateHome}/tarsnap";
tarsnapBackup = pkgs.writeShellScriptBin "tarsnap-backup-helper" ''
date=$(date -u +%Y-%m-%dT%H:%M:%SZ)
echo
echo "Running tarsnap backup for $date"
${lib.getExe pkgs.tarsnap} -c \
--configfile ${config.home.homeDirectory}/.tarsnaprc \
--keyfile ${config.xdg.configHome}/tarsnap/write-only.key \
-f $(uname -n)-$date \
${config.home.homeDirectory}/{dotfiles.nix,Desktop,Development,Documents}
'';
in
{
enable = true;
config = {
Label = "com.tarsnap.tarsnap";
StandardErrorPath = "${logPath}/error.log";
StandardOutPath = "${logPath}/out.log";
StartCalendarInterval = [
{
# every sunday
Weekday = 0;
# at midnight
Hour = 0;
Minute = 0;
}
];
Program = lib.getExe tarsnapBackup;
};
2022-10-10 21:54:15 +00:00
};
}