From b543388729dd73389777cfd08d436da0f32815fd Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 9 Apr 2018 12:36:53 +0200 Subject: =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom/lvm-snapshots.nix | 15 +++++++++------ odin.nix | 2 +- 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 cfg = config.services.lvm-snapshots; snapshotMount = name: "${cfg.mountPoint}/${if isNull cfg.snapshots."${name}".mountName then name else cfg.snapshots."${name}".mountName}"; + snapshotName = name: "${name}-snapshot"; snapshotConfig = { options = { @@ -58,11 +59,13 @@ in { config = mkIf (cfg != {}) { + boot.kernelModules = [ "dm_snapshot" ]; + system.activationScripts = mapAttrs' (name: scfg: nameValuePair ("lvm-mountpoint" + name) '' mkdir -p ${snapshotMount name} '') cfg.snapshots; - systemd.services = mapAttrs' (name: scfg: nameValuePair ("lvm-snapshot@" + name) { + systemd.services = mapAttrs' (name: scfg: nameValuePair ("lvm-snapshot@" + snapshotName name) { enable = true; unitConfig = { @@ -71,8 +74,8 @@ in { serviceConfig = with pkgs; { Type = "oneshot"; - ExecStart = "${devicemapper}/bin/lvcreate -s ${scfg.cowSize} --name ${name} ${scfg.VG}/${scfg.LV}"; - ExecStop = "${devicemapper}/bin/lvremove ${scfg.VG}/${name}"; + ExecStart = "${devicemapper}/bin/lvcreate -s ${scfg.cowSize} --name ${snapshotName name} ${scfg.VG}/${scfg.LV}"; + ExecStop = "${devicemapper}/bin/lvremove ${scfg.VG}/${snapshotName name}"; RemainAfterExit = true; }; }) cfg.snapshots; @@ -85,13 +88,13 @@ in { StopWhenUnneeded = !scfg.persist; }; - bindsTo = [ ("lvm-snapshot@" + name + ".service") ]; - after = [ ("lvm-snapshot@" + name + ".service") ]; + bindsTo = [ ("lvm-snapshot@" + snapshotName name + ".service") ]; + after = [ ("lvm-snapshot@" + snapshotName name + ".service") ]; options = mkIf scfg.readOnly "ro"; where = snapshotMount name; - what = "/dev/" + scfg.VG + "/" + name; + what = "/dev/" + scfg.VG + "/" + snapshotName name; }) cfg.snapshots; }; } diff --git a/odin.nix b/odin.nix index 50fd557a..588ff9e4 100644 --- a/odin.nix +++ b/odin.nix @@ -150,7 +150,7 @@ services.lvm-snapshots = { snapshots = { - snapshot-mail = { + mail = { LV = "mail"; VG = "raid6"; }; -- cgit v1.2.3