add top-level layout type

This commit is contained in:
lassulus 2018-07-19 21:52:11 +02:00
parent 6232ab3078
commit 7262439401
2 changed files with 63 additions and 51 deletions

View file

@ -1,5 +1,8 @@
# usage: nix-instantiate --eval --json --strict example/config.nix | jq . # usage: nix-instantiate --eval --json --strict example/config.nix | jq .
{ {
type = "layout";
content = {
"/dev/sda" = {
type = "table"; type = "table";
format = "gpt"; format = "gpt";
partitions = [ partitions = [
@ -54,4 +57,6 @@
}; };
} }
]; ];
};
};
} }

View file

@ -12,6 +12,9 @@ let
}; };
}; };
config.layout = q: x:
foldl' mergeAttrs {} (mapAttrsToList (name: config-f { device = name; }) x.content);
config.lv = q: x: config.lv = q: x:
config-f { device = "/dev/${q.vgname}/${q.name}"; } x.content; config-f { device = "/dev/${q.vgname}/${q.name}"; } x.content;
@ -35,6 +38,10 @@ let
mkfs.${x.format} ${q.device} mkfs.${x.format} ${q.device}
''; '';
format.layout = q: x: ''
${concatStrings (mapAttrsToList (name: format-f { device = name; }) x.content)}
'';
format.lv = q: x: '' format.lv = q: x: ''
lvcreate -L ${x.size} -n ${q.name} ${q.vgname} lvcreate -L ${x.size} -n ${q.name} ${q.vgname}
${format-f { device = "/dev/${q.vgname}/${q.name}"; } x.content} ${format-f { device = "/dev/${q.vgname}/${q.name}"; } x.content}