From ac9bdefdec93f8b62c2c39fe8766379ce0f5cddf Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Tue, 21 Mar 2023 18:47:41 +0100 Subject: [PATCH] WIP --- modules/programs/borgmatic.nix | 48 ++++++++++++++----- .../borgmatic/basic-configuration.nix | 29 +++++------ 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/modules/programs/borgmatic.nix b/modules/programs/borgmatic.nix index 7d221cee5823..d0c022041ae9 100644 --- a/modules/programs/borgmatic.nix +++ b/modules/programs/borgmatic.nix @@ -44,7 +44,7 @@ let }; configModule = types.submodule ({ config, ... }: { - config.location.extraConfig.exclude_from = + config.extraConfig.location.exclude_from = mkIf config.location.excludeHomeManagerSymlinks (mkAfter [ (toString hmExcludeFile) ]); options = { @@ -73,8 +73,6 @@ let default = false; example = true; }; - - extraConfig = extraConfigOption; }; storage = { @@ -84,7 +82,6 @@ let example = literalExpression ''"''${pkgs.password-store}/bin/pass borg-repo"''; }; - extraConfig = extraConfigOption; }; retention = { @@ -101,8 +98,6 @@ let keepWeekly = mkRetentionOption "weekly"; keepMonthly = mkRetentionOption "monthly"; keepYearly = mkRetentionOption "yearly"; - - extraConfig = extraConfigOption; }; consistency = { @@ -131,8 +126,6 @@ let ]; ''; }; - - extraConfig = extraConfigOption; }; extraConfig = extraConfigOption; @@ -154,10 +147,10 @@ let 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; @@ -167,13 +160,42 @@ let 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; + }; + consistency = removeNullValues { checks = config.consistency.checks; }; } // config.extraConfig); in { meta.maintainers = [ maintainers.DamienCassou ]; + imports = [ + (mkRenamedOptionModule [ "programs" "borgmatic" "location" "extraConfig" ] [ + "programs" + "borgmatic" + "extraConfig" + "location" + ]) + + (mkRenamedOptionModule [ "programs" "borgmatic" "storage" "extraConfig" ] [ + "programs" + "borgmatic" + "extraConfig" + "storage" + ]) + + (mkRenamedOptionModule [ + "programs" + "borgmatic" + "retention" + "extraConfig" + ] [ "programs" "borgmatic" "extraConfig" "retention" ]) + + (mkRenamedOptionModule [ + "programs" + "borgmatic" + "consistency" + "extraConfig" + ] [ "programs" "borgmatic" "extraConfig" "consistency" ]) + ]; + options = { programs.borgmatic = { enable = mkEnableOption "Borgmatic"; diff --git a/tests/modules/programs/borgmatic/basic-configuration.nix b/tests/modules/programs/borgmatic/basic-configuration.nix index 4f9633a6db14..66c6b083a7e3 100644 --- a/tests/modules/programs/borgmatic/basic-configuration.nix +++ b/tests/modules/programs/borgmatic/basic-configuration.nix @@ -12,21 +12,13 @@ in { location = { sourceDirectories = [ "/my-stuff-to-backup" ]; repositories = [ "/mnt/disk1" "/mnt/disk2" ]; - extraConfig = { - one_file_system = true; - exclude_patterns = [ "*.swp" ]; - }; }; - storage = { - encryptionPasscommand = "fetch-the-password.sh"; - extraConfig = { checkpoint_interval = 200; }; - }; + storage = { encryptionPasscommand = "fetch-the-password.sh"; }; retention = { keepWithin = "14d"; keepSecondly = 12; - extraConfig = { prefix = "hostname"; }; }; consistency = { @@ -40,11 +32,16 @@ in { frequency = "4 weeks"; } ]; - - extraConfig = { prefix = "hostname"; }; }; extraConfig = { + location = { + one_file_system = true; + exclude_patterns = [ "*.swp" ]; + }; + storage = { checkpoint_interval = 200; }; + retention = { prefix = "hostname"; }; + consistency = { prefix = "hostname"; }; hooks = { before_actions = [ "echo Starting actions." ]; }; }; }; @@ -69,22 +66,22 @@ in { builtins.elemAt backups.main.location.repositories 1 }" expectations[location.one_file_system]="${ - boolToString backups.main.location.extraConfig.one_file_system + boolToString backups.main.extraConfig.location.one_file_system }" expectations[location.exclude_patterns[0]]="${ - builtins.elemAt backups.main.location.extraConfig.exclude_patterns 0 + builtins.elemAt backups.main.extraConfig.location.exclude_patterns 0 }" expectations[storage.encryption_passcommand]="${backups.main.storage.encryptionPasscommand}" expectations[storage.checkpoint_interval]="${ - toString backups.main.storage.extraConfig.checkpoint_interval + toString backups.main.extraConfig.storage.checkpoint_interval }" expectations[retention.keep_within]="${backups.main.retention.keepWithin}" expectations[retention.keep_secondly]="${ toString backups.main.retention.keepSecondly }" - expectations[retention.prefix]="${backups.main.retention.extraConfig.prefix}" + expectations[retention.prefix]="${backups.main.extraConfig.retention.prefix}" expectations[consistency.checks[0].name]="${ (builtins.elemAt backups.main.consistency.checks 0).name @@ -98,7 +95,7 @@ in { expectations[consistency.checks[1].frequency]="${ (builtins.elemAt backups.main.consistency.checks 1).frequency }" - expectations[consistency.prefix]="${backups.main.consistency.extraConfig.prefix}" + expectations[consistency.prefix]="${backups.main.extraConfig.consistency.prefix}" expectations[hooks.before_actions[0]]="echo Starting actions."