From 0e8c5d1e6757ea049e5e58c2d56701748d99fe6a Mon Sep 17 00:00:00 2001 From: lassulus Date: Wed, 25 Jul 2018 01:25:04 +0200 Subject: layout -> devices, expose body --- example/config.nix | 4 ++-- lib/default.nix | 41 ++++++++++++++++++----------------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/example/config.nix b/example/config.nix index 36c0950..be02f23 100644 --- a/example/config.nix +++ b/example/config.nix @@ -1,8 +1,8 @@ # usage: nix-instantiate --eval --json --strict example/config.nix | jq . { - type = "layout"; + type = "devices"; content = { - "/dev/sda" = { + sda = { type = "table"; format = "gpt"; partitions = [ diff --git a/lib/default.nix b/lib/default.nix index cbb6a9d..7bfa59a 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,9 +1,11 @@ with import ; with builtins; -let +let { + + body.config = q: x: config.${x.type} q x; + body.create = q: x: create.${x.type} q x; - config-f = q: x: config.${x.type} q x; config.filesystem = q: x: { fileSystems.${x.mountpoint} = { @@ -12,51 +14,49 @@ let }; }; - config.layout = q: x: - foldl' mergeAttrs {} (mapAttrsToList (name: config-f { device = name; }) x.content); + config.devices = q: x: + foldl' mergeAttrs {} (mapAttrsToList (name: body.config { device = "/dev/${name}"; }) x.content); config.luks = q: x: { boot.initrd.luks.devices.${x.name}.device = q.device; - } // config-f { device = "/dev/mapper/${x.name}"; } x.content; + } // body.config { device = "/dev/mapper/${x.name}"; } x.content; config.lv = q: x: - config-f { device = "/dev/${q.vgname}/${q.name}"; } x.content; + body.config { device = "/dev/${q.vgname}/${q.name}"; } x.content; config.lvm = q: x: - foldl' mergeAttrs {} (mapAttrsToList (name: config-f { inherit name; vgname = x.name; }) x.lvs); + foldl' mergeAttrs {} (mapAttrsToList (name: body.config { inherit name; vgname = x.name; }) x.lvs); config.partition = q: x: - config-f { device = q.device + toString q.index; } x.content; + body.config { device = q.device + toString q.index; } x.content; config.table = q: x: - foldl' mergeAttrs {} (imap (index: config-f (q // { inherit index; })) x.partitions); - + foldl' mergeAttrs {} (imap (index: body.config (q // { inherit index; })) x.partitions); - create-f = q: x: create.${x.type} q x; create.filesystem = q: x: '' mkfs.${x.format} ${q.device} ''; - create.layout = q: x: '' - ${concatStrings (mapAttrsToList (name: create-f { device = name; }) x.content)} + create.devices = q: x: '' + ${concatStrings (mapAttrsToList (name: body.create { device = "/dev/${name}"; }) x.content)} ''; create.luks = q: x: '' cryptsetup -q luksFormat ${q.device} ${x.keyfile} cryptsetup luksOpen ${q.device} ${x.name} --key-file ${x.keyfile} - ${create-f { device = "/dev/mapper/${x.name}"; } x.content} + ${body.create { device = "/dev/mapper/${x.name}"; } x.content} ''; create.lv = q: x: '' lvcreate -L ${x.size} -n ${q.name} ${q.vgname} - ${create-f { device = "/dev/${q.vgname}/${q.name}"; } x.content} + ${body.create { device = "/dev/${q.vgname}/${q.name}"; } x.content} ''; create.lvm = q: x: '' pvcreate ${q.device} vgcreate ${x.name} ${q.device} - ${concatStrings (mapAttrsToList (name: create-f { inherit name; vgname = x.name; }) x.lvs)} + ${concatStrings (mapAttrsToList (name: body.create { inherit name; vgname = x.name; }) x.lvs)} ''; create.partition = q: x: '' @@ -64,16 +64,11 @@ let ${optionalString (x.bootable or false) '' parted -s ${q.device} set ${toString q.index} boot on ''} - ${create-f { device = q.device + toString q.index; } x.content} + ${body.create { device = q.device + toString q.index; } x.content} ''; create.table = q: x: '' parted -s ${q.device} mklabel ${x.format} - ${concatStrings (imap (index: create-f (q // { inherit index; })) x.partitions)} + ${concatStrings (imap (index: body.create (q // { inherit index; })) x.partitions)} ''; -in - { - config = device: config-f { inherit device; }; - create = device: create-f { inherit device; }; - } -- cgit v1.2.3