diff options
| -rw-r--r-- | custom/borgbackup.nix | 16 | ||||
| -rw-r--r-- | custom/btrfs-snapshots.nix | 11 | ||||
| -rw-r--r-- | custom/lvm-snapshots.nix | 7 |
3 files changed, 16 insertions, 18 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; |
diff --git a/custom/btrfs-snapshots.nix b/custom/btrfs-snapshots.nix index 39e0bf0c..034b5019 100644 --- a/custom/btrfs-snapshots.nix +++ b/custom/btrfs-snapshots.nix | |||
| @@ -5,21 +5,16 @@ with lib; | |||
| 5 | let | 5 | let |
| 6 | cfg = config.services.btrfs-snapshots; | 6 | cfg = config.services.btrfs-snapshots; |
| 7 | 7 | ||
| 8 | snapshotMount = str: "${cfg.mountPoint}/${cfg.mountPrefix}${str}"; | 8 | snapshotMount = str: "${str}${cfg.mountSuffix}"; |
| 9 | in { | 9 | in { |
| 10 | options = { | 10 | options = { |
| 11 | 11 | ||
| 12 | services.btrfs-snapshots = { | 12 | services.btrfs-snapshots = { |
| 13 | enable = mkEnableOption "a systemd unit for btrfs snapshots"; | 13 | enable = mkEnableOption "a systemd unit for btrfs snapshots"; |
| 14 | 14 | ||
| 15 | mountPoint = mkOption { | 15 | mountSuffix = mkOption { |
| 16 | type = types.path; | ||
| 17 | default = "/mnt"; | ||
| 18 | }; | ||
| 19 | |||
| 20 | mountPrefix = mkOption { | ||
| 21 | type = types.str; | 16 | type = types.str; |
| 22 | default = "snapshot-"; | 17 | default = ".snapshot"; |
| 23 | }; | 18 | }; |
| 24 | 19 | ||
| 25 | readOnly = mkOption { | 20 | readOnly = mkOption { |
diff --git a/custom/lvm-snapshots.nix b/custom/lvm-snapshots.nix index 98c64330..13cbf421 100644 --- a/custom/lvm-snapshots.nix +++ b/custom/lvm-snapshots.nix | |||
| @@ -7,7 +7,7 @@ let | |||
| 7 | cfg = config.services.lvm-snapshots; | 7 | cfg = config.services.lvm-snapshots; |
| 8 | 8 | ||
| 9 | snapshotMount = name: "${cfg.mountPoint}/${if isNull cfg.snapshots."${name}".mountName then name else cfg.snapshots."${name}".mountName}"; | 9 | snapshotMount = name: "${cfg.mountPoint}/${if isNull cfg.snapshots."${name}".mountName then name else cfg.snapshots."${name}".mountName}"; |
| 10 | snapshotName = name: "${name}-snapshot"; | 10 | snapshotName = name: "${name}-${cfg.mountSuffix}"; |
| 11 | 11 | ||
| 12 | snapshotConfig = { | 12 | snapshotConfig = { |
| 13 | options = { | 13 | options = { |
| @@ -53,6 +53,11 @@ in { | |||
| 53 | type = types.path; | 53 | type = types.path; |
| 54 | default = "/mnt"; | 54 | default = "/mnt"; |
| 55 | }; | 55 | }; |
| 56 | |||
| 57 | mountSuffix = mkOption { | ||
| 58 | type = types.str; | ||
| 59 | default = "-snapshot"; | ||
| 60 | }; | ||
| 56 | }; | 61 | }; |
| 57 | }; | 62 | }; |
| 58 | 63 | ||
