mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
Merge pull request #153346 from Stunkymonkey/borg-persistent
nixos/borgbackup: Add a persistentTimer option.
This commit is contained in:
commit
363577461d
1 changed files with 29 additions and 1 deletions
|
@ -99,7 +99,18 @@ let
|
||||||
BORG_REPO = cfg.repo;
|
BORG_REPO = cfg.repo;
|
||||||
inherit (cfg) extraArgs extraInitArgs extraCreateArgs extraPruneArgs;
|
inherit (cfg) extraArgs extraInitArgs extraCreateArgs extraPruneArgs;
|
||||||
} // (mkPassEnv cfg) // cfg.environment;
|
} // (mkPassEnv cfg) // cfg.environment;
|
||||||
inherit (cfg) startAt;
|
};
|
||||||
|
|
||||||
|
mkBackupTimers = name: cfg:
|
||||||
|
nameValuePair "borgbackup-job-${name}" {
|
||||||
|
description = "BorgBackup job ${name} timer";
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
Persistent = cfg.persistentTimer;
|
||||||
|
OnCalendar = cfg.startAt;
|
||||||
|
};
|
||||||
|
# if remote-backup wait for network
|
||||||
|
after = optional (cfg.persistentTimer && !isLocalPath cfg.repo) "network-online.target";
|
||||||
};
|
};
|
||||||
|
|
||||||
# utility function around makeWrapper
|
# utility function around makeWrapper
|
||||||
|
@ -321,6 +332,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 {
|
user = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = ''
|
description = ''
|
||||||
|
@ -695,6 +719,10 @@ in {
|
||||||
# A repo named "foo" is mapped to systemd.services.borgbackup-repo-foo
|
# A repo named "foo" is mapped to systemd.services.borgbackup-repo-foo
|
||||||
// mapAttrs' mkRepoService repos;
|
// mapAttrs' mkRepoService repos;
|
||||||
|
|
||||||
|
# A job named "foo" is mapped to systemd.timers.borgbackup-job-foo
|
||||||
|
# only generate the timer if interval (startAt) is set
|
||||||
|
systemd.timers = mapAttrs' mkBackupTimers (filterAttrs (_: cfg: cfg.startAt != []) jobs);
|
||||||
|
|
||||||
users = mkMerge (mapAttrsToList mkUsersConfig repos);
|
users = mkMerge (mapAttrsToList mkUsersConfig repos);
|
||||||
|
|
||||||
environment.systemPackages = with pkgs; [ borgbackup ] ++ (mapAttrsToList mkBorgWrapper jobs);
|
environment.systemPackages = with pkgs; [ borgbackup ] ++ (mapAttrsToList mkBorgWrapper jobs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue