summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2018-04-14 17:48:12 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2018-04-14 17:48:12 +0200
commitffec7ef64c332281472d406a8b1b3995df1e5a25 (patch)
treef72ce6e7090c1ddebd8a616e96bcbcf582070994
parente72a0525c28fc1c0eacb5776ad295b7841f078cd (diff)
downloadnixos-ffec7ef64c332281472d406a8b1b3995df1e5a25.tar
nixos-ffec7ef64c332281472d406a8b1b3995df1e5a25.tar.gz
nixos-ffec7ef64c332281472d406a8b1b3995df1e5a25.tar.bz2
nixos-ffec7ef64c332281472d406a8b1b3995df1e5a25.tar.xz
nixos-ffec7ef64c332281472d406a8b1b3995df1e5a25.zip
-rw-r--r--custom/borgbackup.nix10
-rw-r--r--custom/lvm-snapshots.nix8
2 files changed, 8 insertions, 10 deletions
diff --git a/custom/borgbackup.nix b/custom/borgbackup.nix
index 9c696393..865cda3b 100644
--- a/custom/borgbackup.nix
+++ b/custom/borgbackup.nix
@@ -19,7 +19,7 @@ let
19 19
20 pathType = if cfg.snapshots == "lvm" then types.submodule lvmPath else types.path; 20 pathType = if cfg.snapshots == "lvm" then types.submodule lvmPath else types.path;
21 21
22 systemdPath = path: if cfg.snapshots == "lvm" then escapeSystemdPath "${path.VG}/${path.LV}" else escapeSystemdPath 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 withPrefix = path: config.services.btrfs-snapshots.mountPrefix + path;
25 25
@@ -90,9 +90,9 @@ in {
90 90
91 services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true; 91 services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true;
92 92
93 services.lvm-snapshots.snapshots = mkIf (cfg.snapshots == "lvm") (listToAttrs (map (path: nameValuePair (escapeSystemdPath (path.VG + "/" + path.LV)) { 93 services.lvm-snapshots.snapshots = mkIf (cfg.snapshots == "lvm") (listToAttrs (map (path: nameValuePair (path.VG + "-" + path.LV) {
94 inherit (path) LV VG; 94 inherit (path) LV VG;
95 mountName = withPrefix (systemdPath path); 95 mountName = withPrefix (VG + "-" + LV);
96 }) (unique (flatten (mapAttrsToList (target: tCfg: tCfg.paths) cfg.targets))))); 96 }) (unique (flatten (mapAttrsToList (target: tCfg: tCfg.paths) cfg.targets)))));
97 97
98 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}" {
@@ -146,12 +146,12 @@ in {
146 unitConfig = { 146 unitConfig = {
147 AssertPathIsDirectory = mkIf (tCfg.lock != null) "/var/lock"; 147 AssertPathIsDirectory = mkIf (tCfg.lock != null) "/var/lock";
148 DefaultDependencies = false; 148 DefaultDependencies = false;
149 RequiresMountsFor = mkIf (cfg.snapshots == "lvm") [ "${mountPoint}/${withPrefix "%i"}" ]; 149 RequiresMountsFor = mkIf (cfg.snapshots == "lvm") [ "${mountPoint}/${withPrefix "%I"}" ];
150 }; 150 };
151 151
152 serviceConfig = { 152 serviceConfig = {
153 Type = "oneshot"; 153 Type = "oneshot";
154 WorkingDirectory = if (cfg.snapshots == null) then "%p" else "${mountPoint}/${withPrefix "%i"}"; 154 WorkingDirectory = if (cfg.snapshots == null) then "%I" else (if (cfg.snapshots == "lvm") then "${mountPoint}/${withPrefix "%I"}" else "${mountPoint}/${withPrefix "%i"}");
155 Nice = 15; 155 Nice = 15;
156 IOSchedulingClass = 2; 156 IOSchedulingClass = 2;
157 IOSchedulingPriority = 7; 157 IOSchedulingPriority = 7;
diff --git a/custom/lvm-snapshots.nix b/custom/lvm-snapshots.nix
index c78de3a5..5e4557f3 100644
--- a/custom/lvm-snapshots.nix
+++ b/custom/lvm-snapshots.nix
@@ -9,8 +9,6 @@ let
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}-snapshot";
11 11
12 instance = scfg: escapeSystemdPath (scfg.VG + "/" + scfg.LV);
13
14 snapshotConfig = { 12 snapshotConfig = {
15 options = { 13 options = {
16 LV = mkOption { 14 LV = mkOption {
@@ -67,7 +65,7 @@ in {
67 mkdir -p ${snapshotMount name} 65 mkdir -p ${snapshotMount name}
68 '') cfg.snapshots; 66 '') cfg.snapshots;
69 67
70 systemd.services = mapAttrs' (name: scfg: nameValuePair ("lvm-snapshot@" + instance scfg) { 68 systemd.services = mapAttrs' (name: scfg: nameValuePair ("lvm-snapshot@" + escapeSystemdPath name) {
71 enable = true; 69 enable = true;
72 70
73 description = "LVM-snapshot of ${scfg.VG}/${scfg.LV}"; 71 description = "LVM-snapshot of ${scfg.VG}/${scfg.LV}";
@@ -111,8 +109,8 @@ in {
111 StopWhenUnneeded = !scfg.persist; 109 StopWhenUnneeded = !scfg.persist;
112 }; 110 };
113 111
114 bindsTo = [ ("lvm-snapshot@" + instance scfg + ".service") ]; 112 bindsTo = [ ("lvm-snapshot@" + escapeSystemdPath name + ".service") ];
115 after = [ ("lvm-snapshot@" + instance scfg + ".service") ]; 113 after = [ ("lvm-snapshot@" + escapeSystemdPath name + ".service") ];
116 114
117 options = concatStringsSep "," ([ "noauto" ] ++ optional scfg.readOnly "ro"); 115 options = concatStringsSep "," ([ "noauto" ] ++ optional scfg.readOnly "ro");
118 116