summaryrefslogtreecommitdiff
path: root/custom
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-12-17 14:30:52 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-12-17 14:30:52 +0100
commit01d2927a4eb9f2753c5e2c4e5af820dca18cc9fc (patch)
tree20a8646fb37bc7da8b61fa861b91307452bfa069 /custom
parent468c0971cae3515d9c8dfa854b75b614d08d9251 (diff)
downloadnixos-01d2927a4eb9f2753c5e2c4e5af820dca18cc9fc.tar
nixos-01d2927a4eb9f2753c5e2c4e5af820dca18cc9fc.tar.gz
nixos-01d2927a4eb9f2753c5e2c4e5af820dca18cc9fc.tar.bz2
nixos-01d2927a4eb9f2753c5e2c4e5af820dca18cc9fc.tar.xz
nixos-01d2927a4eb9f2753c5e2c4e5af820dca18cc9fc.zip
Diffstat (limited to 'custom')
-rw-r--r--custom/borgbackup.nix40
1 files changed, 30 insertions, 10 deletions
diff --git a/custom/borgbackup.nix b/custom/borgbackup.nix
index 9047d72e..70647334 100644
--- a/custom/borgbackup.nix
+++ b/custom/borgbackup.nix
@@ -69,7 +69,17 @@ in {
69 }; 69 };
70 }) (flatten (mapAttrsToList (target: tCfg: map (path: { inherit target path tCfg; }) tCfg.paths) cfg.targets))); 70 }) (flatten (mapAttrsToList (target: tCfg: map (path: { inherit target path tCfg; }) tCfg.paths) cfg.targets)));
71 71
72 systemd.services = listToAttrs (map ({ target, path, tCfg }: nameValuePair "borgbackup-${target}@${path}" (let 72 systemd.timers = mapAttrs (target: tCfg: nameValuePair "borgbackup-prune-${target}" {
73 wantedBy = [ "timers.target" ];
74
75 timerConfig = {
76 Persistent = false;
77 OnBootSec = tCfg.interval;
78 OnUnitInactiveSec = tCfg.interval;
79 };
80 }) cfg.targets;
81
82 systemd.services = mapAttrs (target: tCfg: nameValuePair "borgbackup-${target}@" (let
73 deps = flatten [ 83 deps = flatten [
74 (optional (cfg.snapshots == "btrfs") "btrfs-snapshot@%p.service") 84 (optional (cfg.snapshots == "btrfs") "btrfs-snapshot@%p.service")
75 (optional tCfg.network "network-online.target") 85 (optional tCfg.network "network-online.target")
@@ -92,16 +102,10 @@ in {
92 --patterns-from .backup \ 102 --patterns-from .backup \
93 --one-file-system \ 103 --one-file-system \
94 --compression auto,lzma \ 104 --compression auto,lzma \
95 ${tCfg.repo}::${cfg.prefix}${path}-{utcnow} 105 ${tCfg.repo}::${cfg.prefix}$1-{utcnow}
96 ''; 106 '';
97 in if tCfg.lock == null then borgCmd else "flock -xo /var/lock/${tCfg.lock} ${borgCmd}"; 107 in if tCfg.lock == null then borgCmd else "flock -xo /var/lock/${tCfg.lock} ${borgCmd}";
98 108 scriptArgs = "%i";
99 preStop = mkIf (hasAttr path tCfg.prune) ''
100 borg prune \
101 --prefix "${cfg.prefix}${path}" \
102 ${concatStringsSep " " tCfg.prune."${path}"} \
103 ${tCfg.repo}
104 '';
105 109
106 unitConfig = { 110 unitConfig = {
107 AssertPathIsDirectory = mkIf (tCfg.lock != null) "/var/lock"; 111 AssertPathIsDirectory = mkIf (tCfg.lock != null) "/var/lock";
@@ -115,6 +119,22 @@ in {
115 IOSchedulingPriority = 7; 119 IOSchedulingPriority = 7;
116 SuccessExitStatus = [1 2]; 120 SuccessExitStatus = [1 2];
117 }; 121 };
118 })) (flatten (mapAttrsToList (target: tCfg: map (path: { inherit target path tCfg; }) tCfg.paths) cfg.targets))); 122 })) cfg.targets;
123
124 systemd.services = mapAttrs (target: tCfg: nameValuePair "borgbackup-prune-${target}" {
125 bindsTo = "network-online.target";
126 after = "network-online.target";
127
128 script = concatStringsSep "\n" (mapAttrsToList (''
129 borg prune \
130 --prefix "${cfg.prefix}${path}" \
131 ${concatStringsSep " " tCfg.prune."${path}"} \
132 ${tCfg.repo}
133 '') tCfg.prune);
134
135 serviceConfig = {
136 Type = "oneshot";
137 };
138 }) cfg.targets;
119 }; 139 };
120} 140}