summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2018-04-09 12:36:53 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2018-04-09 12:36:53 +0200
commitb543388729dd73389777cfd08d436da0f32815fd (patch)
tree513a1690ca36d0caa11d72f018e0e0f07359b278
parentd72b85f52945bc057a3d598f51eddb55837fd465 (diff)
downloadnixos-b543388729dd73389777cfd08d436da0f32815fd.tar
nixos-b543388729dd73389777cfd08d436da0f32815fd.tar.gz
nixos-b543388729dd73389777cfd08d436da0f32815fd.tar.bz2
nixos-b543388729dd73389777cfd08d436da0f32815fd.tar.xz
nixos-b543388729dd73389777cfd08d436da0f32815fd.zip
-rw-r--r--custom/lvm-snapshots.nix15
-rw-r--r--odin.nix2
2 files changed, 10 insertions, 7 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}
diff --git a/odin.nix b/odin.nix
index 50fd557a..588ff9e4 100644
--- a/odin.nix
+++ b/odin.nix
@@ -150,7 +150,7 @@
150 150
151 services.lvm-snapshots = { 151 services.lvm-snapshots = {
152 snapshots = { 152 snapshots = {
153 snapshot-mail = { 153 mail = {
154 LV = "mail"; 154 LV = "mail";
155 VG = "raid6"; 155 VG = "raid6";
156 }; 156 };