summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/backup/borgbackup.nix
diff options
context:
space:
mode:
authorblargg <tomjankauski@gmail.com>2021-05-17 18:54:13 -0700
committerFelix Buehler <account@buehler.rocks>2022-01-17 15:42:37 +0100
commit697198834c6a861d30b8fbfe4162525c87155e00 (patch)
tree05947ff56704609741f1f892ea692a0ed46edf40 /nixos/modules/services/backup/borgbackup.nix
parent1ea75adb020b250a8459b6cadcb66543b6c1e217 (diff)
nixos/borgbackup: Add a persistentTimer option.
Persistent starts the backup service on power on if it was missed while the system was powered down, for example.
Diffstat (limited to 'nixos/modules/services/backup/borgbackup.nix')
-rw-r--r--nixos/modules/services/backup/borgbackup.nix24
1 files changed, 24 insertions, 0 deletions
diff --git a/nixos/modules/services/backup/borgbackup.nix b/nixos/modules/services/backup/borgbackup.nix
index 6804055a2940..cb2c4d6381f9 100644
--- a/nixos/modules/services/backup/borgbackup.nix
+++ b/nixos/modules/services/backup/borgbackup.nix
@@ -102,6 +102,14 @@ let
inherit (cfg) startAt;
};
+ mkBackupTimers = name: cfg:
+ nameValuePair "borgbackup-job-${name}" {
+ description = "BorgBackup job ${name} timer";
+ timerConfig = {
+ Persistent = cfg.persistentTimer;
+ };
+ };
+
# utility function around makeWrapper
mkWrapperDrv = {
original, name, set ? {}
@@ -321,6 +329,19 @@ in {
'';
};
+ persistentTimer = mkOption {
+ default = false;
+ type = types.bool;
+ example = true;
+ description = literalDocBook ''
+ Set the <literal>persistentTimer</literal> option for the
+ <citerefentry><refentrytitle>systemd.timer</refentrytitle>
+ <manvolnum>5</manvolnum></citerefentry>
+ which triggers the backup immediately if the last trigger
+ was missed (e.g. if the system was powered down).
+ '';
+ };
+
user = mkOption {
type = types.str;
description = ''
@@ -695,6 +716,9 @@ in {
# A repo named "foo" is mapped to systemd.services.borgbackup-repo-foo
// mapAttrs' mkRepoService repos;
+ # A job named "foo" is mapped to systemd.timers.borgbackup-job-foo
+ systemd.timers = mapAttrs' mkBackupTimers jobs;
+
users = mkMerge (mapAttrsToList mkUsersConfig repos);
environment.systemPackages = with pkgs; [ borgbackup ] ++ (mapAttrsToList mkBorgWrapper jobs);