summaryrefslogtreecommitdiff
path: root/custom/lvm-snapshots.nix
diff options
context:
space:
mode:
Diffstat (limited to 'custom/lvm-snapshots.nix')
-rw-r--r--custom/lvm-snapshots.nix15
1 files changed, 9 insertions, 6 deletions
diff --git a/custom/lvm-snapshots.nix b/custom/lvm-snapshots.nix
index 74b33570..ef4a97c4 100644
--- a/custom/lvm-snapshots.nix
+++ b/custom/lvm-snapshots.nix
@@ -6,6 +6,7 @@ let
6 cfg = config.services.lvm-snapshots; 6 cfg = config.services.lvm-snapshots;
7 7
8 snapshotMount = name: "${cfg.mountPoint}/${if isNull cfg.snapshots."${name}".mountName then name else cfg.snapshots."${name}".mountName}"; 8 snapshotMount = name: "${cfg.mountPoint}/${if isNull cfg.snapshots."${name}".mountName then name else cfg.snapshots."${name}".mountName}";
9 snapshotName = name: "${name}-snapshot";
9 10
10 snapshotConfig = { 11 snapshotConfig = {
11 options = { 12 options = {
@@ -58,11 +59,13 @@ in {
58 59
59 config = mkIf (cfg != {}) { 60 config = mkIf (cfg != {}) {
60 61
62 boot.kernelModules = [ "dm_snapshot" ];
63
61 system.activationScripts = mapAttrs' (name: scfg: nameValuePair ("lvm-mountpoint" + name) '' 64 system.activationScripts = mapAttrs' (name: scfg: nameValuePair ("lvm-mountpoint" + name) ''
62 mkdir -p ${snapshotMount name} 65 mkdir -p ${snapshotMount name}
63 '') cfg.snapshots; 66 '') cfg.snapshots;
64 67
65 systemd.services = mapAttrs' (name: scfg: nameValuePair ("lvm-snapshot@" + name) { 68 systemd.services = mapAttrs' (name: scfg: nameValuePair ("lvm-snapshot@" + snapshotName name) {
66 enable = true; 69 enable = true;
67 70
68 unitConfig = { 71 unitConfig = {
@@ -71,8 +74,8 @@ in {
71 74
72 serviceConfig = with pkgs; { 75 serviceConfig = with pkgs; {
73 Type = "oneshot"; 76 Type = "oneshot";
74 ExecStart = "${devicemapper}/bin/lvcreate -s ${scfg.cowSize} --name ${name} ${scfg.VG}/${scfg.LV}"; 77 ExecStart = "${devicemapper}/bin/lvcreate -s ${scfg.cowSize} --name ${snapshotName name} ${scfg.VG}/${scfg.LV}";
75 ExecStop = "${devicemapper}/bin/lvremove ${scfg.VG}/${name}"; 78 ExecStop = "${devicemapper}/bin/lvremove ${scfg.VG}/${snapshotName name}";
76 RemainAfterExit = true; 79 RemainAfterExit = true;
77 }; 80 };
78 }) cfg.snapshots; 81 }) cfg.snapshots;
@@ -85,13 +88,13 @@ in {
85 StopWhenUnneeded = !scfg.persist; 88 StopWhenUnneeded = !scfg.persist;
86 }; 89 };
87 90
88 bindsTo = [ ("lvm-snapshot@" + name + ".service") ]; 91 bindsTo = [ ("lvm-snapshot@" + snapshotName name + ".service") ];
89 after = [ ("lvm-snapshot@" + name + ".service") ]; 92 after = [ ("lvm-snapshot@" + snapshotName name + ".service") ];
90 93
91 options = mkIf scfg.readOnly "ro"; 94 options = mkIf scfg.readOnly "ro";
92 95
93 where = snapshotMount name; 96 where = snapshotMount name;
94 what = "/dev/" + scfg.VG + "/" + name; 97 what = "/dev/" + scfg.VG + "/" + snapshotName name;
95 }) cfg.snapshots; 98 }) cfg.snapshots;
96 }; 99 };
97} 100}