From d4a5076ea8c2c063c45e0165f9f75f69ef583e20 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Sun, 15 Oct 2023 00:38:55 +0200 Subject: [PATCH] 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. --- modules/programs/borgmatic.nix | 39 ++++++++----------- .../borgmatic/basic-configuration.nix | 38 +++++++++--------- .../exclude-hm-symlinks-nothing-else.nix | 2 +- .../borgmatic/exclude-hm-symlinks.nix | 4 +- .../borgmatic/include-hm-symlinks.nix | 2 +- 5 files changed, 38 insertions(+), 47 deletions(-) diff --git a/modules/programs/borgmatic.nix b/modules/programs/borgmatic.nix index 5e84edbe..e1be117c 100644 --- a/modules/programs/borgmatic.nix +++ b/modules/programs/borgmatic.nix @@ -152,29 +152,22 @@ let hmExcludeFile = pkgs.writeText "hm-symlinks.txt" hmExcludePatterns; writeConfig = config: - generators.toYAML { } { - location = removeNullValues { - source_directories = config.location.sourceDirectories; - repositories = config.location.repositories; - } // config.location.extraConfig; - storage = removeNullValues { - encryption_passcommand = config.storage.encryptionPasscommand; - } // config.storage.extraConfig; - retention = removeNullValues { - keep_within = config.retention.keepWithin; - keep_secondly = config.retention.keepSecondly; - keep_minutely = config.retention.keepMinutely; - keep_hourly = config.retention.keepHourly; - keep_daily = config.retention.keepDaily; - keep_weekly = config.retention.keepWeekly; - keep_monthly = config.retention.keepMonthly; - 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; - }; + generators.toYAML { } (removeNullValues ({ + source_directories = config.location.sourceDirectories; + repositories = config.location.repositories; + encryption_passcommand = config.storage.encryptionPasscommand; + keep_within = config.retention.keepWithin; + keep_secondly = config.retention.keepSecondly; + keep_minutely = config.retention.keepMinutely; + keep_hourly = config.retention.keepHourly; + keep_daily = config.retention.keepDaily; + keep_weekly = config.retention.keepWeekly; + keep_monthly = config.retention.keepMonthly; + keep_yearly = config.retention.keepYearly; + checks = config.consistency.checks; + } // config.location.extraConfig // config.storage.extraConfig + // config.retention.extraConfig // config.consistency.extraConfig + // config.output.extraConfig // config.hooks.extraConfig)); in { meta.maintainers = [ maintainers.DamienCassou ]; diff --git a/tests/modules/programs/borgmatic/basic-configuration.nix b/tests/modules/programs/borgmatic/basic-configuration.nix index 50b4a0f2..a02c4764 100644 --- a/tests/modules/programs/borgmatic/basic-configuration.nix +++ b/tests/modules/programs/borgmatic/basic-configuration.nix @@ -62,50 +62,48 @@ in { declare -A expectations - expectations[location.source_directories[0]]="${ + expectations[source_directories[0]]="${ builtins.elemAt backups.main.location.sourceDirectories 0 }" - expectations[location.repositories[0]]="${ + expectations[repositories[0]]="${ builtins.elemAt backups.main.location.repositories 0 }" - expectations[location.repositories[1]]="${ + expectations[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 }" - expectations[location.exclude_patterns[0]]="${ + expectations[exclude_patterns[0]]="${ builtins.elemAt backups.main.location.extraConfig.exclude_patterns 0 }" - expectations[storage.encryption_passcommand]="${backups.main.storage.encryptionPasscommand}" - expectations[storage.checkpoint_interval]="${ + expectations[encryption_passcommand]="${backups.main.storage.encryptionPasscommand}" + expectations[checkpoint_interval]="${ toString backups.main.storage.extraConfig.checkpoint_interval }" - expectations[retention.keep_within]="${backups.main.retention.keepWithin}" - expectations[retention.keep_secondly]="${ + expectations[keep_within]="${backups.main.retention.keepWithin}" + expectations[keep_secondly]="${ 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 }" - expectations[consistency.checks[0].frequency]="${ + expectations[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 }" - expectations[consistency.checks[1].frequency]="${ + expectations[checks[1].frequency]="${ (builtins.elemAt backups.main.consistency.checks 1).frequency }" - expectations[consistency.prefix]="${backups.main.consistency.extraConfig.prefix}" - expectations[output.color]="${ - boolToString backups.main.output.extraConfig.color - }" - expectations[hooks.before_actions[0]]="${ + 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 }" @@ -120,7 +118,7 @@ in { fi 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 fail "Expected one_file_system to be true but it was $one_file_system" fi diff --git a/tests/modules/programs/borgmatic/exclude-hm-symlinks-nothing-else.nix b/tests/modules/programs/borgmatic/exclude-hm-symlinks-nothing-else.nix index 1d238b91..cadd7fd2 100644 --- a/tests/modules/programs/borgmatic/exclude-hm-symlinks-nothing-else.nix +++ b/tests/modules/programs/borgmatic/exclude-hm-symlinks-nothing-else.nix @@ -27,7 +27,7 @@ in { 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' grep --quiet "$expected_content" "$hmExclusionsFile" diff --git a/tests/modules/programs/borgmatic/exclude-hm-symlinks.nix b/tests/modules/programs/borgmatic/exclude-hm-symlinks.nix index 8635b28d..bc0e5012 100644 --- a/tests/modules/programs/borgmatic/exclude-hm-symlinks.nix +++ b/tests/modules/programs/borgmatic/exclude-hm-symlinks.nix @@ -28,7 +28,7 @@ in { declare -A expectations - expectations[location.exclude_from[0]]="${excludeFile}" + expectations[exclude_from[0]]="${excludeFile}" yq=${pkgs.yq-go}/bin/yq @@ -41,7 +41,7 @@ in { fi 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' grep --quiet "$expected_content" "$hmExclusionsFile" diff --git a/tests/modules/programs/borgmatic/include-hm-symlinks.nix b/tests/modules/programs/borgmatic/include-hm-symlinks.nix index f4f5bfcd..dd9908b5 100644 --- a/tests/modules/programs/borgmatic/include-hm-symlinks.nix +++ b/tests/modules/programs/borgmatic/include-hm-symlinks.nix @@ -28,7 +28,7 @@ in { declare -A expectations - expectations[location.exclude_from[0]]="${excludeFile}" + expectations[exclude_from[0]]="${excludeFile}" yq=${pkgs.yq-go}/bin/yq