summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2018-07-31 21:40:57 +0200
committerlassulus <lassulus@lassul.us>2018-07-31 21:47:23 +0200
commit9cbf541974bfe67a84f2450f97a8ccad52c6cd89 (patch)
treece663029e38a5a265832aac563dc0617be109143
parente8f7aa94c20ce43b6977e82fe8ef1f9cc2c07d6b (diff)
lib: add mount
-rw-r--r--example/default.nix1
-rw-r--r--lib/default.nix44
2 files changed, 45 insertions, 0 deletions
diff --git a/example/default.nix b/example/default.nix
index 4cd8ed6..0fa59c0 100644
--- a/example/default.nix
+++ b/example/default.nix
@@ -5,4 +5,5 @@ with import ../lib;
{
config = config "/dev/sda" (import ./config.nix);
create = create "/dev/sda" (import ./config.nix);
+ mount = mount "/dev/sda" (import ./config.nix);
}
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);
+
+}