2022-01-27 15:01:24 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
# using the restic cli:
|
|
|
|
# load credentials into shell via: export $(cat /path/to/credentials/file | xargs)
|
|
|
|
# useful commands for analysing restic stats [snapshot-id], restic diff [s1] [s2],
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
with builtins;
|
|
|
|
let hasAnyAttr = flip (attrset: any (flip hasAttr attrset));
|
|
|
|
in {
|
2022-05-01 16:44:29 +02:00
|
|
|
resticConfig = args@{ name, ripgrep ? false, paths ? [ ], ignorePatterns ? [ ]
|
|
|
|
, extraPruneOpts ? [ ], ... }:
|
2022-01-27 15:01:24 +01:00
|
|
|
assert !hasAnyAttr [
|
|
|
|
"initialize"
|
|
|
|
"repository"
|
|
|
|
"s3CredentialsFile"
|
|
|
|
"passwordFile"
|
|
|
|
"pruneOpts"
|
|
|
|
] args;
|
2022-05-01 16:44:29 +02:00
|
|
|
assert (args ? paths);
|
|
|
|
assert (ripgrep || (!ripgrep && !(args ? ignorePatterns)));
|
|
|
|
{
|
2022-01-27 15:01:24 +01:00
|
|
|
initialize = true;
|
|
|
|
repository = "b2:felschr-backups:/${name}";
|
|
|
|
environmentFile = "/etc/nixos/secrets/restic/b2";
|
|
|
|
passwordFile = "/etc/nixos/secrets/restic/password";
|
2022-05-01 16:44:29 +02:00
|
|
|
timerConfig.OnCalendar = "daily";
|
|
|
|
paths = if ripgrep then null else paths;
|
|
|
|
dynamicFilesFrom = if ripgrep then
|
|
|
|
let
|
|
|
|
files = foldl (a: b: "${a} ${b}") "" paths;
|
|
|
|
ignoreFile = builtins.toFile "ignore"
|
|
|
|
(foldl (a: b: a + "\n" + b) "" ignorePatterns);
|
|
|
|
in ''
|
|
|
|
${pkgs.ripgrep}/bin/rg \
|
|
|
|
--files ${files} \
|
|
|
|
--ignore-file ${ignoreFile} \
|
|
|
|
| sed "s/\[/\\\[/" | sed "s/\]/\\\]/"
|
|
|
|
''
|
|
|
|
else
|
|
|
|
null;
|
2022-01-27 15:01:24 +01:00
|
|
|
pruneOpts = [
|
|
|
|
"--keep-daily 7"
|
|
|
|
"--keep-weekly 4"
|
|
|
|
"--keep-monthly 3"
|
|
|
|
"--keep-yearly 1"
|
|
|
|
] ++ extraPruneOpts;
|
2022-05-01 16:44:29 +02:00
|
|
|
} // (removeAttrs args [
|
|
|
|
"name"
|
|
|
|
"ripgrep"
|
|
|
|
"paths"
|
|
|
|
"ignorePatterns"
|
|
|
|
"extraPruneOpts"
|
|
|
|
]);
|
2022-01-27 15:01:24 +01:00
|
|
|
}
|