summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--custom/borgbackup.nix8
-rw-r--r--custom/btrfs-snapshots.nix4
-rw-r--r--custom/lvm-snapshots.nix1
3 files changed, 7 insertions, 6 deletions
diff --git a/custom/borgbackup.nix b/custom/borgbackup.nix
index fe380695..ab826757 100644
--- a/custom/borgbackup.nix
+++ b/custom/borgbackup.nix
@@ -21,6 +21,10 @@ let
21 21
22 systemdPath = path: if cfg.snapshots == "lvm" then escapeSystemdPath "${path.VG}/${path.LV}" else escapeSystemdPath path; 22 systemdPath = path: if cfg.snapshots == "lvm" then escapeSystemdPath "${path.VG}/${path.LV}" else escapeSystemdPath path;
23 23
24 withPrefix = path: config.services.btrfs-snapshots.mountPrefix + path;
25
26 mountPoint = if cfg.snapshots == "lvm" then config.services.lvm-snapshots.mountPoint else config.services.btrfs-snapshots.mountPoint;
27
24 targetOptions = { 28 targetOptions = {
25 options = { 29 options = {
26 repo = mkOption { 30 repo = mkOption {
@@ -88,7 +92,7 @@ in {
88 92
89 services.lvm-snapshots.snapshots = mkIf (cfg.snapshots == "lvm") (listToAttrs (map (path: nameValuePair (escapeSystemdPath path.LV) { 93 services.lvm-snapshots.snapshots = mkIf (cfg.snapshots == "lvm") (listToAttrs (map (path: nameValuePair (escapeSystemdPath path.LV) {
90 inherit (path) LV VG; 94 inherit (path) LV VG;
91 mountName = "snapshot-${systemdPath path}"; 95 mountName = withPrefix (systemdPath path);
92 }) (unique (flatten (mapAttrsToList (target: tCfg: tCfg.paths) cfg.targets))))); 96 }) (unique (flatten (mapAttrsToList (target: tCfg: tCfg.paths) cfg.targets)))));
93 97
94 systemd.timers = (listToAttrs (map ({ target, path, tCfg }: nameValuePair "borgbackup-${target}@${systemdPath path}" { 98 systemd.timers = (listToAttrs (map ({ target, path, tCfg }: nameValuePair "borgbackup-${target}@${systemdPath path}" {
@@ -143,7 +147,7 @@ in {
143 147
144 serviceConfig = { 148 serviceConfig = {
145 Type = "oneshot"; 149 Type = "oneshot";
146 WorkingDirectory = if (cfg.snapshots == null) then "%p" else "/mnt/snapshot-%i"; 150 WorkingDirectory = if (cfg.snapshots == null) then "%p" else "${mountPoint}/${withPrefix "%i"}";
147 Nice = 15; 151 Nice = 15;
148 IOSchedulingClass = 2; 152 IOSchedulingClass = 2;
149 IOSchedulingPriority = 7; 153 IOSchedulingPriority = 7;
diff --git a/custom/btrfs-snapshots.nix b/custom/btrfs-snapshots.nix
index 9dc3f1f8..39e0bf0c 100644
--- a/custom/btrfs-snapshots.nix
+++ b/custom/btrfs-snapshots.nix
@@ -13,13 +13,11 @@ in {
13 enable = mkEnableOption "a systemd unit for btrfs snapshots"; 13 enable = mkEnableOption "a systemd unit for btrfs snapshots";
14 14
15 mountPoint = mkOption { 15 mountPoint = mkOption {
16 readOnly = true;
17 type = types.path; 16 type = types.path;
18 default = "/mnt"; 17 default = "/mnt";
19 }; 18 };
20 19
21 mountPrefix = mkOption { 20 mountPrefix = mkOption {
22 readOnly = true;
23 type = types.str; 21 type = types.str;
24 default = "snapshot-"; 22 default = "snapshot-";
25 }; 23 };
@@ -41,7 +39,7 @@ in {
41 config = mkIf cfg.enable { 39 config = mkIf cfg.enable {
42 40
43 system.activationScripts."btrfs-snapshots" = '' 41 system.activationScripts."btrfs-snapshots" = ''
44 mkdir -p ${mountPoint} 42 mkdir -p ${cfg.mountPoint}
45 ''; 43 '';
46 44
47 systemd.services."btrfs-snapshot@" = { 45 systemd.services."btrfs-snapshot@" = {
diff --git a/custom/lvm-snapshots.nix b/custom/lvm-snapshots.nix
index c7f6416e..af8b61bb 100644
--- a/custom/lvm-snapshots.nix
+++ b/custom/lvm-snapshots.nix
@@ -50,7 +50,6 @@ in {
50 50
51 mountPoint = mkOption { 51 mountPoint = mkOption {
52 type = types.path; 52 type = types.path;
53 readOnly = true;
54 default = "/mnt"; 53 default = "/mnt";
55 }; 54 };
56 }; 55 };