mirror of
https://github.com/nix-community/home-manager
synced 2024-11-18 17:19:45 +01:00
16311f1d3c
Borgmatic has support for Borg's pattern matching. It is mutually exclusive with the existing `sourceDirectories` option, so assertions have been added to make sure that both are not set at the same time (but also that at least one of them is). Additionally, tests have been added to test the following configurations: `patterns` instead of `sourceDirectories`, both at the same time, and neither.
58 lines
1.4 KiB
Nix
58 lines
1.4 KiB
Nix
{ config, pkgs, ... }:
|
|
|
|
let
|
|
|
|
boolToString = bool: if bool then "true" else "false";
|
|
backups = config.programs.borgmatic.backups;
|
|
|
|
in {
|
|
programs.borgmatic = {
|
|
enable = true;
|
|
backups = {
|
|
main = {
|
|
location = {
|
|
patterns = [
|
|
"R /home/user"
|
|
"+ home/user/stuff-to-backup"
|
|
"+ home/user/junk/important-file"
|
|
"- home/user/junk"
|
|
];
|
|
repositories = [ "/mnt/backup-drive" ];
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
test.stubs.borgmatic = { };
|
|
|
|
nmt.script = ''
|
|
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
|
assertFileExists $config_file
|
|
|
|
declare -A expectations
|
|
|
|
expectations[patterns[0]]="${
|
|
builtins.elemAt backups.main.location.patterns 0
|
|
}"
|
|
expectations[patterns[1]]="${
|
|
builtins.elemAt backups.main.location.patterns 1
|
|
}"
|
|
expectations[patterns[2]]="${
|
|
builtins.elemAt backups.main.location.patterns 2
|
|
}"
|
|
expectations[patterns[3]]="${
|
|
builtins.elemAt backups.main.location.patterns 3
|
|
}"
|
|
|
|
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'"
|
|
fi
|
|
done
|
|
'';
|
|
}
|