Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienCassou committed Mar 21, 2023
1 parent 34b435a commit ac9bdef
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
48 changes: 35 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,8 +126,6 @@ let
];
'';
};

extraConfig = extraConfigOption;
};

extraConfig = extraConfigOption;
Expand All @@ -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;
Expand All @@ -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";
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 ac9bdef

Please sign in to comment.