borgmatic: improve support for version 1.8.0

The configuration file format of borgmatic has changed in version
1.8.0:
https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/NEWS

This commit makes Home Manager generate borgmatic's configuration file
using the new format.

Even though the NEWS file indicates that old configuration files are
compatible, this is not 100% the case: empty sections work fine in old
borgmatic but stop working in new ones. I've reported the bug upstream
by email as I couldn't create an account on the forge.
This commit is contained in:
Damien Cassou 2023-10-15 00:38:55 +02:00 committed by GitHub
parent 9a2ce65697
commit d4a5076ea8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 47 deletions

View file

@ -152,29 +152,22 @@ let
hmExcludeFile = pkgs.writeText "hm-symlinks.txt" hmExcludePatterns; hmExcludeFile = pkgs.writeText "hm-symlinks.txt" hmExcludePatterns;
writeConfig = config: writeConfig = config:
generators.toYAML { } { generators.toYAML { } (removeNullValues ({
location = removeNullValues { source_directories = config.location.sourceDirectories;
source_directories = config.location.sourceDirectories; repositories = config.location.repositories;
repositories = config.location.repositories; encryption_passcommand = config.storage.encryptionPasscommand;
} // config.location.extraConfig; keep_within = config.retention.keepWithin;
storage = removeNullValues { keep_secondly = config.retention.keepSecondly;
encryption_passcommand = config.storage.encryptionPasscommand; keep_minutely = config.retention.keepMinutely;
} // config.storage.extraConfig; keep_hourly = config.retention.keepHourly;
retention = removeNullValues { keep_daily = config.retention.keepDaily;
keep_within = config.retention.keepWithin; keep_weekly = config.retention.keepWeekly;
keep_secondly = config.retention.keepSecondly; keep_monthly = config.retention.keepMonthly;
keep_minutely = config.retention.keepMinutely; keep_yearly = config.retention.keepYearly;
keep_hourly = config.retention.keepHourly; checks = config.consistency.checks;
keep_daily = config.retention.keepDaily; } // config.location.extraConfig // config.storage.extraConfig
keep_weekly = config.retention.keepWeekly; // config.retention.extraConfig // config.consistency.extraConfig
keep_monthly = config.retention.keepMonthly; // config.output.extraConfig // config.hooks.extraConfig));
keep_yearly = config.retention.keepYearly;
} // config.retention.extraConfig;
consistency = removeNullValues { checks = config.consistency.checks; }
// config.consistency.extraConfig;
output = config.output.extraConfig;
hooks = config.hooks.extraConfig;
};
in { in {
meta.maintainers = [ maintainers.DamienCassou ]; meta.maintainers = [ maintainers.DamienCassou ];

View file

@ -62,50 +62,48 @@ in {
declare -A expectations declare -A expectations
expectations[location.source_directories[0]]="${ expectations[source_directories[0]]="${
builtins.elemAt backups.main.location.sourceDirectories 0 builtins.elemAt backups.main.location.sourceDirectories 0
}" }"
expectations[location.repositories[0]]="${ expectations[repositories[0]]="${
builtins.elemAt backups.main.location.repositories 0 builtins.elemAt backups.main.location.repositories 0
}" }"
expectations[location.repositories[1]]="${ expectations[repositories[1]]="${
builtins.elemAt backups.main.location.repositories 1 builtins.elemAt backups.main.location.repositories 1
}" }"
expectations[location.one_file_system]="${ expectations[one_file_system]="${
boolToString backups.main.location.extraConfig.one_file_system boolToString backups.main.location.extraConfig.one_file_system
}" }"
expectations[location.exclude_patterns[0]]="${ expectations[exclude_patterns[0]]="${
builtins.elemAt backups.main.location.extraConfig.exclude_patterns 0 builtins.elemAt backups.main.location.extraConfig.exclude_patterns 0
}" }"
expectations[storage.encryption_passcommand]="${backups.main.storage.encryptionPasscommand}" expectations[encryption_passcommand]="${backups.main.storage.encryptionPasscommand}"
expectations[storage.checkpoint_interval]="${ expectations[checkpoint_interval]="${
toString backups.main.storage.extraConfig.checkpoint_interval toString backups.main.storage.extraConfig.checkpoint_interval
}" }"
expectations[retention.keep_within]="${backups.main.retention.keepWithin}" expectations[keep_within]="${backups.main.retention.keepWithin}"
expectations[retention.keep_secondly]="${ expectations[keep_secondly]="${
toString backups.main.retention.keepSecondly toString backups.main.retention.keepSecondly
}" }"
expectations[retention.prefix]="${backups.main.retention.extraConfig.prefix}" expectations[prefix]="${backups.main.retention.extraConfig.prefix}"
expectations[consistency.checks[0].name]="${ expectations[checks[0].name]="${
(builtins.elemAt backups.main.consistency.checks 0).name (builtins.elemAt backups.main.consistency.checks 0).name
}" }"
expectations[consistency.checks[0].frequency]="${ expectations[checks[0].frequency]="${
(builtins.elemAt backups.main.consistency.checks 0).frequency (builtins.elemAt backups.main.consistency.checks 0).frequency
}" }"
expectations[consistency.checks[1].name]="${ expectations[checks[1].name]="${
(builtins.elemAt backups.main.consistency.checks 1).name (builtins.elemAt backups.main.consistency.checks 1).name
}" }"
expectations[consistency.checks[1].frequency]="${ expectations[checks[1].frequency]="${
(builtins.elemAt backups.main.consistency.checks 1).frequency (builtins.elemAt backups.main.consistency.checks 1).frequency
}" }"
expectations[consistency.prefix]="${backups.main.consistency.extraConfig.prefix}" expectations[prefix]="${backups.main.consistency.extraConfig.prefix}"
expectations[output.color]="${ expectations[color]="${boolToString backups.main.output.extraConfig.color}"
boolToString backups.main.output.extraConfig.color expectations[before_actions[0]]="${
}"
expectations[hooks.before_actions[0]]="${
builtins.elemAt backups.main.hooks.extraConfig.before_actions 0 builtins.elemAt backups.main.hooks.extraConfig.before_actions 0
}" }"
@ -120,7 +118,7 @@ in {
fi fi
done done
one_file_system=$($yq ".location.one_file_system" $config_file) one_file_system=$($yq ".one_file_system" $config_file)
if [[ $one_file_system != "true" ]]; then if [[ $one_file_system != "true" ]]; then
fail "Expected one_file_system to be true but it was $one_file_system" fail "Expected one_file_system to be true but it was $one_file_system"
fi fi

View file

@ -27,7 +27,7 @@ in {
yq=${pkgs.yq-go}/bin/yq yq=${pkgs.yq-go}/bin/yq
hmExclusionsFile=$($yq '.location.exclude_from[0]' $config_file) hmExclusionsFile=$($yq '.exclude_from[0]' $config_file)
expected_content='/home/hm-user/.config/borgmatic.d/main.yaml' expected_content='/home/hm-user/.config/borgmatic.d/main.yaml'
grep --quiet "$expected_content" "$hmExclusionsFile" grep --quiet "$expected_content" "$hmExclusionsFile"

View file

@ -28,7 +28,7 @@ in {
declare -A expectations declare -A expectations
expectations[location.exclude_from[0]]="${excludeFile}" expectations[exclude_from[0]]="${excludeFile}"
yq=${pkgs.yq-go}/bin/yq yq=${pkgs.yq-go}/bin/yq
@ -41,7 +41,7 @@ in {
fi fi
done done
hmExclusionsFile=$($yq '.location.exclude_from[1]' $config_file) hmExclusionsFile=$($yq '.exclude_from[1]' $config_file)
expected_content='/home/hm-user/.config/borgmatic.d/main.yaml' expected_content='/home/hm-user/.config/borgmatic.d/main.yaml'
grep --quiet "$expected_content" "$hmExclusionsFile" grep --quiet "$expected_content" "$hmExclusionsFile"

View file

@ -28,7 +28,7 @@ in {
declare -A expectations declare -A expectations
expectations[location.exclude_from[0]]="${excludeFile}" expectations[exclude_from[0]]="${excludeFile}"
yq=${pkgs.yq-go}/bin/yq yq=${pkgs.yq-go}/bin/yq