summaryrefslogtreecommitdiff
path: root/custom/borgbackup.nix
diff options
context:
space:
mode:
Diffstat (limited to 'custom/borgbackup.nix')
-rw-r--r--custom/borgbackup.nix19
1 files changed, 9 insertions, 10 deletions
diff --git a/custom/borgbackup.nix b/custom/borgbackup.nix
index 3871af0a..b292f6f2 100644
--- a/custom/borgbackup.nix
+++ b/custom/borgbackup.nix
@@ -21,9 +21,9 @@ let
21 21
22 systemdPath = path: escapeSystemdPath (if cfg.snapshots == "lvm" then "${path.VG}-${path.LV}" else path); 22 systemdPath = path: escapeSystemdPath (if cfg.snapshots == "lvm" then "${path.VG}-${path.LV}" else path);
23 23
24 withPrefix = path: config.services.btrfs-snapshots.mountPrefix + path; 24 withSuffix = path: path + (if cfg.snapshots == "btrfs" then config.services.btrfs-snapshots.mountSuffix else config.services.lvm-snapshots.mountSuffix);
25 25
26 mountPoint = if cfg.snapshots == "lvm" then config.services.lvm-snapshots.mountPoint else config.services.btrfs-snapshots.mountPoint; 26 mountPoint = if cfg.snapshots == "lvm" then config.services.lvm-snapshots.mountPoint else "";
27 27
28 targetOptions = { 28 targetOptions = {
29 options = { 29 options = {
@@ -86,18 +86,17 @@ in {
86 }; 86 };
87 }; 87 };
88 88
89 imports = [ 89 imports =
90 ./lvm-snapshots.nix 90 [ ./lvm-snapshots.nix
91 ./btrfs-snapshots.nix 91 ./btrfs-snapshots.nix
92 ]; 92 ];
93 93
94 config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) { 94 config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) {
95
96 services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true; 95 services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true;
97 96
98 services.lvm-snapshots.snapshots = mkIf (cfg.snapshots == "lvm") (listToAttrs (map (path: nameValuePair (path.VG + "-" + path.LV) { 97 services.lvm-snapshots.snapshots = mkIf (cfg.snapshots == "lvm") (listToAttrs (map (path: nameValuePair (path.VG + "-" + path.LV) {
99 inherit (path) LV VG; 98 inherit (path) LV VG;
100 mountName = withPrefix (path.VG + "-" + path.LV); 99 mountName = withSuffix (path.VG + "-" + path.LV);
101 }) (unique (flatten (mapAttrsToList (target: tCfg: tCfg.paths) cfg.targets))))); 100 }) (unique (flatten (mapAttrsToList (target: tCfg: tCfg.paths) cfg.targets)))));
102 101
103 systemd.targets."timers-borg" = { 102 systemd.targets."timers-borg" = {
@@ -159,12 +158,12 @@ in {
159 unitConfig = { 158 unitConfig = {
160 AssertPathIsDirectory = mkIf (tCfg.lock != null) "/var/lock"; 159 AssertPathIsDirectory = mkIf (tCfg.lock != null) "/var/lock";
161 DefaultDependencies = false; 160 DefaultDependencies = false;
162 RequiresMountsFor = mkIf (cfg.snapshots == "lvm") [ "${mountPoint}/${withPrefix "%I"}" ]; 161 RequiresMountsFor = mkIf (cfg.snapshots == "lvm") [ "${mountPoint}/${withSuffix "%I"}" ];
163 }; 162 };
164 163
165 serviceConfig = { 164 serviceConfig = {
166 Type = "oneshot"; 165 Type = "oneshot";
167 WorkingDirectory = if (cfg.snapshots == null) then "%I" else (if (cfg.snapshots == "lvm") then "${mountPoint}/${withPrefix "%I"}" else "${mountPoint}/${withPrefix "%i"}"); 166 WorkingDirectory = if (cfg.snapshots == null) then "%I" else (if (cfg.snapshots == "lvm") then "${withSuffix "%I"}" else "${withSuffix "%f"}");
168 Nice = 15; 167 Nice = 15;
169 IOSchedulingClass = 2; 168 IOSchedulingClass = 2;
170 IOSchedulingPriority = 7; 169 IOSchedulingPriority = 7;