2022-09-25 17:27:04 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2023-05-12 22:08:12 +00:00
|
|
|
|
2022-09-25 17:27:04 +00:00
|
|
|
boolToString = bool: if bool then "true" else "false";
|
|
|
|
backups = config.programs.borgmatic.backups;
|
2023-05-12 22:08:12 +00:00
|
|
|
|
2022-09-25 17:27:04 +00:00
|
|
|
in {
|
2023-05-12 22:08:12 +00:00
|
|
|
programs.borgmatic = {
|
|
|
|
enable = true;
|
|
|
|
backups = {
|
|
|
|
main = {
|
|
|
|
location = {
|
|
|
|
sourceDirectories = [ "/my-stuff-to-backup" ];
|
2023-11-01 13:41:58 +00:00
|
|
|
repositories = [
|
|
|
|
"/mnt/disk1"
|
|
|
|
{ path = "/mnt/disk2"; }
|
|
|
|
{
|
|
|
|
path = "/mnt/disk3";
|
|
|
|
label = "disk3";
|
|
|
|
}
|
|
|
|
];
|
2023-05-12 22:08:12 +00:00
|
|
|
extraConfig = {
|
|
|
|
one_file_system = true;
|
|
|
|
exclude_patterns = [ "*.swp" ];
|
2022-09-25 17:27:04 +00:00
|
|
|
};
|
2023-05-12 22:08:12 +00:00
|
|
|
};
|
2022-09-25 17:27:04 +00:00
|
|
|
|
2023-05-12 22:08:12 +00:00
|
|
|
storage = {
|
|
|
|
encryptionPasscommand = "fetch-the-password.sh";
|
|
|
|
extraConfig = { checkpoint_interval = 200; };
|
|
|
|
};
|
2022-09-25 17:27:04 +00:00
|
|
|
|
2023-05-12 22:08:12 +00:00
|
|
|
retention = {
|
|
|
|
keepWithin = "14d";
|
|
|
|
keepSecondly = 12;
|
|
|
|
extraConfig = { prefix = "hostname"; };
|
|
|
|
};
|
2022-09-25 17:27:04 +00:00
|
|
|
|
2023-05-12 22:08:12 +00:00
|
|
|
consistency = {
|
|
|
|
checks = [
|
|
|
|
{
|
|
|
|
name = "repository";
|
|
|
|
frequency = "2 weeks";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "archives";
|
|
|
|
frequency = "4 weeks";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
extraConfig = { prefix = "hostname"; };
|
2022-09-25 17:27:04 +00:00
|
|
|
};
|
2023-06-18 05:57:41 +00:00
|
|
|
|
|
|
|
output = { extraConfig = { color = false; }; };
|
|
|
|
|
|
|
|
hooks = {
|
|
|
|
extraConfig = { before_actions = [ "echo Starting actions." ]; };
|
|
|
|
};
|
2022-09-25 17:27:04 +00:00
|
|
|
};
|
|
|
|
};
|
2023-05-12 22:08:12 +00:00
|
|
|
};
|
2022-09-25 17:27:04 +00:00
|
|
|
|
2023-05-12 22:08:12 +00:00
|
|
|
test.stubs.borgmatic = { };
|
|
|
|
|
|
|
|
nmt.script = ''
|
|
|
|
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
|
|
|
assertFileExists $config_file
|
|
|
|
|
|
|
|
declare -A expectations
|
|
|
|
|
2023-10-14 22:38:55 +00:00
|
|
|
expectations[source_directories[0]]="${
|
2023-05-12 22:08:12 +00:00
|
|
|
builtins.elemAt backups.main.location.sourceDirectories 0
|
|
|
|
}"
|
2023-11-01 13:41:58 +00:00
|
|
|
expectations[repositories[0].path]="${
|
|
|
|
(builtins.elemAt backups.main.location.repositories 0).path
|
|
|
|
}"
|
|
|
|
expectations[repositories[1].path]="${
|
|
|
|
(builtins.elemAt backups.main.location.repositories 1).path
|
|
|
|
}"
|
|
|
|
expectations[repositories[2].path]="${
|
|
|
|
(builtins.elemAt backups.main.location.repositories 2).path
|
2023-05-12 22:08:12 +00:00
|
|
|
}"
|
2023-11-01 13:41:58 +00:00
|
|
|
expectations[repositories[2].label]="${
|
|
|
|
(builtins.elemAt backups.main.location.repositories 2).label
|
2023-05-12 22:08:12 +00:00
|
|
|
}"
|
2023-10-14 22:38:55 +00:00
|
|
|
expectations[one_file_system]="${
|
2023-05-12 22:08:12 +00:00
|
|
|
boolToString backups.main.location.extraConfig.one_file_system
|
|
|
|
}"
|
2023-10-14 22:38:55 +00:00
|
|
|
expectations[exclude_patterns[0]]="${
|
2023-05-12 22:08:12 +00:00
|
|
|
builtins.elemAt backups.main.location.extraConfig.exclude_patterns 0
|
|
|
|
}"
|
|
|
|
|
2023-10-14 22:38:55 +00:00
|
|
|
expectations[encryption_passcommand]="${backups.main.storage.encryptionPasscommand}"
|
|
|
|
expectations[checkpoint_interval]="${
|
2023-05-12 22:08:12 +00:00
|
|
|
toString backups.main.storage.extraConfig.checkpoint_interval
|
|
|
|
}"
|
|
|
|
|
2023-10-14 22:38:55 +00:00
|
|
|
expectations[keep_within]="${backups.main.retention.keepWithin}"
|
|
|
|
expectations[keep_secondly]="${
|
2023-05-12 22:08:12 +00:00
|
|
|
toString backups.main.retention.keepSecondly
|
|
|
|
}"
|
2023-10-14 22:38:55 +00:00
|
|
|
expectations[prefix]="${backups.main.retention.extraConfig.prefix}"
|
2023-05-12 22:08:12 +00:00
|
|
|
|
2023-10-14 22:38:55 +00:00
|
|
|
expectations[checks[0].name]="${
|
2023-05-12 22:08:12 +00:00
|
|
|
(builtins.elemAt backups.main.consistency.checks 0).name
|
|
|
|
}"
|
2023-10-14 22:38:55 +00:00
|
|
|
expectations[checks[0].frequency]="${
|
2023-05-12 22:08:12 +00:00
|
|
|
(builtins.elemAt backups.main.consistency.checks 0).frequency
|
|
|
|
}"
|
2023-10-14 22:38:55 +00:00
|
|
|
expectations[checks[1].name]="${
|
2023-05-12 22:08:12 +00:00
|
|
|
(builtins.elemAt backups.main.consistency.checks 1).name
|
|
|
|
}"
|
2023-10-14 22:38:55 +00:00
|
|
|
expectations[checks[1].frequency]="${
|
2023-05-12 22:08:12 +00:00
|
|
|
(builtins.elemAt backups.main.consistency.checks 1).frequency
|
|
|
|
}"
|
2023-10-14 22:38:55 +00:00
|
|
|
expectations[prefix]="${backups.main.consistency.extraConfig.prefix}"
|
|
|
|
expectations[color]="${boolToString backups.main.output.extraConfig.color}"
|
|
|
|
expectations[before_actions[0]]="${
|
2023-06-18 05:57:41 +00:00
|
|
|
builtins.elemAt backups.main.hooks.extraConfig.before_actions 0
|
|
|
|
}"
|
2023-05-12 22:08:12 +00:00
|
|
|
|
|
|
|
yq=${pkgs.yq-go}/bin/yq
|
|
|
|
|
|
|
|
for filter in "''${!expectations[@]}"; do
|
|
|
|
expected_value="''${expectations[$filter]}"
|
|
|
|
actual_value="$($yq ".$filter" $config_file)"
|
|
|
|
|
|
|
|
if [[ "$actual_value" != "$expected_value" ]]; then
|
|
|
|
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
|
2022-09-25 17:27:04 +00:00
|
|
|
fi
|
2023-05-12 22:08:12 +00:00
|
|
|
done
|
|
|
|
|
2023-10-14 22:38:55 +00:00
|
|
|
one_file_system=$($yq ".one_file_system" $config_file)
|
2023-05-12 22:08:12 +00:00
|
|
|
if [[ $one_file_system != "true" ]]; then
|
|
|
|
fail "Expected one_file_system to be true but it was $one_file_system"
|
|
|
|
fi
|
|
|
|
'';
|
2022-09-25 17:27:04 +00:00
|
|
|
}
|