From 9cbf541974bfe67a84f2450f97a8ccad52c6cd89 Mon Sep 17 00:00:00 2001 From: lassulus Date: Tue, 31 Jul 2018 21:40:57 +0200 Subject: lib: add mount --- lib/default.nix | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'lib') diff --git a/lib/default.nix b/lib/default.nix index d1f6acf..8b08d01 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -5,6 +5,7 @@ let { body.config = q: x: config.${x.type} q x; body.create = q: x: create.${x.type} q x; + body.mount = q: x: mount.${x.type} q x; config.filesystem = q: x: { @@ -72,3 +73,46 @@ let { ${concatStrings (imap (index: body.create (q // { inherit index; })) x.partitions)} ''; + mount.filesystem = q: x: { + fs.${x.mountpoint} = '' + mkdir -p ${x.mountpoint} + mount ${q.device} ${x.mountpoint} + ''; + }; + + mount.devices = q: x: let + z = foldl' recursiveUpdate {} (mapAttrsToList (name: body.mount { device = "/dev/${name}"; }) x.content); + # attrValues returns values sorted by name. This is important, because it + # ensures that "/" is processed before "/foo" etc. + in '' + ${concatStringsSep "\n" (attrValues z.luks)} + ${concatStringsSep "\n" (attrValues z.lvm)} + ${concatStringsSep "\n" (attrValues z.fs)} + ''; + + mount.luks = q: x: ( + recursiveUpdate + (body.mount { device = "/dev/mapper/${x.name}"; } x.content) + {luks.${q.device} = '' + cryptsetup luksOpen ${q.device} ${x.name} --key-file ${x.keyfile} + '';} + ); + + mount.lv = q: x: + body.mount { device = "/dev/${q.vgname}/${q.name}"; } x.content; + + mount.lvm = q: x: ( + recursiveUpdate + (foldl' recursiveUpdate {} (mapAttrsToList (name: body.mount { inherit name; vgname = x.name; }) x.lvs)) + {lvm.${q.device} = '' + vgchange -a y + '';} + ); + + mount.partition = q: x: + body.mount { device = q.device + toString q.index; } x.content; + + mount.table = q: x: + foldl' recursiveUpdate {} (imap (index: body.mount (q // { inherit index; })) x.partitions); + +} -- cgit v1.2.3