Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienCassou committed Mar 31, 2023
1 parent 11a8b48 commit 93982b3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
40 changes: 27 additions & 13 deletions modules/programs/borgmatic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -73,8 +73,6 @@ let
default = false;
example = true;
};

extraConfig = extraConfigOption;
};

storage = {
Expand All @@ -84,7 +82,6 @@ let
example =
literalExpression ''"''${pkgs.password-store}/bin/pass borg-repo"'';
};
extraConfig = extraConfigOption;
};

retention = {
Expand All @@ -101,8 +98,6 @@ let
keepWeekly = mkRetentionOption "weekly";
keepMonthly = mkRetentionOption "monthly";
keepYearly = mkRetentionOption "yearly";

extraConfig = extraConfigOption;
};

consistency = {
Expand Down Expand Up @@ -131,11 +126,31 @@ let
];
'';
};

extraConfig = extraConfigOption;
};

extraConfig = extraConfigOption;

imports = [
(mkRenamedOptionModule [ "location" "extraConfig" ] [
"extraConfig"
"location"
])

(mkRenamedOptionModule [ "storage" "extraConfig" ] [
"extraConfig"
"storage"
])

(mkRenamedOptionModule [ "retention" "extraConfig" ] [
"extraConfig"
"retention"
])

(mkRenamedOptionModule [ "consistency" "extraConfig" ] [
"extraConfig"
"consistency"
])
];
};
});

Expand All @@ -154,10 +169,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;
Expand All @@ -167,9 +182,8 @@ 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 ];
Expand Down
29 changes: 13 additions & 16 deletions tests/modules/programs/borgmatic/basic-configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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." ]; };
};
};
Expand All @@ -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
Expand All @@ -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."
Expand Down

0 comments on commit 93982b3

Please sign in to comment.