mirror of
https://github.com/nix-community/home-manager.git
synced 2026-10-02 19:49:18 +00:00
Add programs.borgmatic.backups.<name>.settings for native borgmatic YAML and generate each backup file from it. The location, storage, retention, and consistency options and the section extraConfig options become deprecated aliases into settings. Warnings name the affected backup. Legacy configurations without overlapping keys produce the same YAML, and Home Manager symlink exclusions still append to exclude_from. Drop the assertions that rejected backups setting both or neither of sourceDirectories and patterns, so native source patterns and database-only backups work.
172 lines
5.2 KiB
Nix
172 lines
5.2 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
realPkgs,
|
|
...
|
|
}:
|
|
|
|
let
|
|
|
|
boolToString = bool: if bool then "true" else "false";
|
|
inherit (config.programs.borgmatic) backups;
|
|
|
|
in
|
|
{
|
|
programs.borgmatic = {
|
|
enable = true;
|
|
backups = {
|
|
main = {
|
|
location = {
|
|
sourceDirectories = [ "/my-stuff-to-backup" ];
|
|
repositories = [
|
|
"/mnt/disk1"
|
|
{ path = "/mnt/disk2"; }
|
|
{
|
|
path = "/mnt/disk3";
|
|
label = "disk3";
|
|
}
|
|
];
|
|
extraConfig = {
|
|
one_file_system = true;
|
|
exclude_patterns = [ "*.swp" ];
|
|
};
|
|
};
|
|
|
|
storage = {
|
|
encryptionPasscommand = "fetch-the-password.sh";
|
|
extraConfig = {
|
|
checkpoint_interval = 200;
|
|
};
|
|
};
|
|
|
|
retention = {
|
|
keepWithin = "14d";
|
|
keepSecondly = 12;
|
|
extraConfig = {
|
|
prefix = "hostname";
|
|
};
|
|
};
|
|
|
|
consistency = {
|
|
checks = [
|
|
{
|
|
name = "repository";
|
|
frequency = "2 weeks";
|
|
}
|
|
{
|
|
name = "archives";
|
|
frequency = "4 weeks";
|
|
}
|
|
{ name = "data"; }
|
|
];
|
|
|
|
extraConfig = {
|
|
prefix = "hostname";
|
|
};
|
|
};
|
|
|
|
output = {
|
|
extraConfig = {
|
|
color = false;
|
|
};
|
|
};
|
|
|
|
hooks = {
|
|
extraConfig = {
|
|
before_actions = [ "echo Starting actions." ];
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
test.asserts.warnings.expected = (import ./warnings.nix { inherit lib; }) {
|
|
file = ./basic-configuration.nix;
|
|
entries = [
|
|
{ from = "hooks.extraConfig"; }
|
|
{ from = "output.extraConfig"; }
|
|
{ from = "consistency.extraConfig"; }
|
|
{ from = "retention.extraConfig"; }
|
|
{ from = "storage.extraConfig"; }
|
|
{ from = "location.extraConfig"; }
|
|
{
|
|
from = "consistency.checks";
|
|
to = "settings.checks";
|
|
changed = true;
|
|
}
|
|
{
|
|
from = "location.repositories";
|
|
to = "settings.repositories";
|
|
changed = true;
|
|
}
|
|
{
|
|
from = "retention.keepSecondly";
|
|
to = "settings.keep_secondly";
|
|
}
|
|
{
|
|
from = "retention.keepWithin";
|
|
to = "settings.keep_within";
|
|
}
|
|
{
|
|
from = "storage.encryptionPasscommand";
|
|
to = "settings.encryption_passcommand";
|
|
}
|
|
{
|
|
from = "location.sourceDirectories";
|
|
to = "settings.source_directories";
|
|
}
|
|
];
|
|
};
|
|
|
|
nmt.script = ''
|
|
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
|
assertFileExists $config_file
|
|
|
|
declare -A expectations
|
|
|
|
expectations[source_directories[0]]="${builtins.elemAt backups.main.location.sourceDirectories 0}"
|
|
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}"
|
|
expectations[repositories[2].label]="${(builtins.elemAt backups.main.location.repositories 2).label}"
|
|
expectations[one_file_system]="${boolToString backups.main.location.extraConfig.one_file_system}"
|
|
expectations[exclude_patterns[0]]="${builtins.elemAt backups.main.location.extraConfig.exclude_patterns 0}"
|
|
|
|
expectations[encryption_passcommand]="${backups.main.storage.encryptionPasscommand}"
|
|
expectations[checkpoint_interval]="${toString backups.main.storage.extraConfig.checkpoint_interval}"
|
|
|
|
expectations[keep_within]="${backups.main.retention.keepWithin}"
|
|
expectations[keep_secondly]="${toString backups.main.retention.keepSecondly}"
|
|
expectations[prefix]="${backups.main.retention.extraConfig.prefix}"
|
|
|
|
expectations[checks[0].name]="${(builtins.elemAt backups.main.consistency.checks 0).name}"
|
|
expectations[checks[0].frequency]="${(builtins.elemAt backups.main.consistency.checks 0).frequency}"
|
|
expectations[checks[1].name]="${(builtins.elemAt backups.main.consistency.checks 1).name}"
|
|
expectations[checks[1].frequency]="${(builtins.elemAt backups.main.consistency.checks 1).frequency}"
|
|
expectations[checks[2].name]="data"
|
|
expectations[prefix]="${backups.main.consistency.extraConfig.prefix}"
|
|
expectations[color]="${boolToString backups.main.output.extraConfig.color}"
|
|
expectations[before_actions[0]]="${builtins.elemAt backups.main.hooks.extraConfig.before_actions 0}"
|
|
|
|
yq=${realPkgs.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
|
|
|
|
if [[ $($yq '.checks[2] | has("frequency")' $config_file) != "false" ]]; then
|
|
fail "Expected checks[2] to omit frequency"
|
|
fi
|
|
|
|
one_file_system=$($yq ".one_file_system" $config_file)
|
|
if [[ $one_file_system != "true" ]]; then
|
|
fail "Expected one_file_system to be true but it was $one_file_system"
|
|
fi
|
|
'';
|
|
}
|