diff options
Diffstat (limited to 'custom/borgbackup.nix')
| -rw-r--r-- | custom/borgbackup.nix | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/custom/borgbackup.nix b/custom/borgbackup.nix index 3871af0a..0db4b5da 100644 --- a/custom/borgbackup.nix +++ b/custom/borgbackup.nix | |||
| @@ -21,7 +21,7 @@ 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 config.services.btrfs-snapshots.mountPoint; |
| 27 | 27 | ||
| @@ -86,18 +86,16 @@ in { | |||
| 86 | }; | 86 | }; |
| 87 | }; | 87 | }; |
| 88 | 88 | ||
| 89 | imports = [ | 89 | imports = |
| 90 | ./lvm-snapshots.nix | 90 | optional (cfg.snapshots == "lvm") ./lvm-snapshots.nix |
| 91 | ./btrfs-snapshots.nix | 91 | ++ optional (cfg.snapshats == "btrfs") ./btrfs-snapshots.nix; |
| 92 | ]; | ||
| 93 | 92 | ||
| 94 | config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) { | 93 | config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) { |
| 95 | |||
| 96 | services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true; | 94 | services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true; |
| 97 | 95 | ||
| 98 | services.lvm-snapshots.snapshots = mkIf (cfg.snapshots == "lvm") (listToAttrs (map (path: nameValuePair (path.VG + "-" + path.LV) { | 96 | services.lvm-snapshots.snapshots = mkIf (cfg.snapshots == "lvm") (listToAttrs (map (path: nameValuePair (path.VG + "-" + path.LV) { |
| 99 | inherit (path) LV VG; | 97 | inherit (path) LV VG; |
| 100 | mountName = withPrefix (path.VG + "-" + path.LV); | 98 | mountName = withSuffix (path.VG + "-" + path.LV); |
| 101 | }) (unique (flatten (mapAttrsToList (target: tCfg: tCfg.paths) cfg.targets))))); | 99 | }) (unique (flatten (mapAttrsToList (target: tCfg: tCfg.paths) cfg.targets))))); |
| 102 | 100 | ||
| 103 | systemd.targets."timers-borg" = { | 101 | systemd.targets."timers-borg" = { |
| @@ -159,12 +157,12 @@ in { | |||
| 159 | unitConfig = { | 157 | unitConfig = { |
| 160 | AssertPathIsDirectory = mkIf (tCfg.lock != null) "/var/lock"; | 158 | AssertPathIsDirectory = mkIf (tCfg.lock != null) "/var/lock"; |
| 161 | DefaultDependencies = false; | 159 | DefaultDependencies = false; |
| 162 | RequiresMountsFor = mkIf (cfg.snapshots == "lvm") [ "${mountPoint}/${withPrefix "%I"}" ]; | 160 | RequiresMountsFor = mkIf (cfg.snapshots == "lvm") [ "${mountPoint}/${withSuffix "%I"}" ]; |
| 163 | }; | 161 | }; |
| 164 | 162 | ||
| 165 | serviceConfig = { | 163 | serviceConfig = { |
| 166 | Type = "oneshot"; | 164 | Type = "oneshot"; |
| 167 | WorkingDirectory = if (cfg.snapshots == null) then "%I" else (if (cfg.snapshots == "lvm") then "${mountPoint}/${withPrefix "%I"}" else "${mountPoint}/${withPrefix "%i"}"); | 165 | WorkingDirectory = if (cfg.snapshots == null) then "%I" else (if (cfg.snapshots == "lvm") then "${withSuffix "%I"}" else "${mountPoint}/${withPrefix "%i"}"); |
| 168 | Nice = 15; | 166 | Nice = 15; |
| 169 | IOSchedulingClass = 2; | 167 | IOSchedulingClass = 2; |
| 170 | IOSchedulingPriority = 7; | 168 | IOSchedulingPriority = 7; |
