1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-25 03:09:47 +01:00

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,15 +152,10 @@ 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;
} // config.location.extraConfig;
storage = removeNullValues {
encryption_passcommand = config.storage.encryptionPasscommand; encryption_passcommand = config.storage.encryptionPasscommand;
} // config.storage.extraConfig;
retention = removeNullValues {
keep_within = config.retention.keepWithin; keep_within = config.retention.keepWithin;
keep_secondly = config.retention.keepSecondly; keep_secondly = config.retention.keepSecondly;
keep_minutely = config.retention.keepMinutely; keep_minutely = config.retention.keepMinutely;
@ -169,12 +164,10 @@ let
keep_weekly = config.retention.keepWeekly; keep_weekly = config.retention.keepWeekly;
keep_monthly = config.retention.keepMonthly; keep_monthly = config.retention.keepMonthly;
keep_yearly = config.retention.keepYearly; keep_yearly = config.retention.keepYearly;
} // config.retention.extraConfig; checks = config.consistency.checks;
consistency = removeNullValues { checks = config.consistency.checks; } } // config.location.extraConfig // config.storage.extraConfig
// config.consistency.extraConfig; // config.retention.extraConfig // config.consistency.extraConfig
output = config.output.extraConfig; // config.output.extraConfig // config.hooks.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