mirror of
https://github.com/nix-community/disko.git
synced 2024-09-11 06:25:33 +03:00
layout -> devices, expose body
This commit is contained in:
parent
d2f8f4a6cf
commit
0e8c5d1e67
@ -1,8 +1,8 @@
|
|||||||
# usage: nix-instantiate --eval --json --strict example/config.nix | jq .
|
# usage: nix-instantiate --eval --json --strict example/config.nix | jq .
|
||||||
{
|
{
|
||||||
type = "layout";
|
type = "devices";
|
||||||
content = {
|
content = {
|
||||||
"/dev/sda" = {
|
sda = {
|
||||||
type = "table";
|
type = "table";
|
||||||
format = "gpt";
|
format = "gpt";
|
||||||
partitions = [
|
partitions = [
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
with import <nixpkgs/lib>;
|
with import <nixpkgs/lib>;
|
||||||
with builtins;
|
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: {
|
config.filesystem = q: x: {
|
||||||
fileSystems.${x.mountpoint} = {
|
fileSystems.${x.mountpoint} = {
|
||||||
@ -12,51 +14,49 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config.layout = q: x:
|
config.devices = q: x:
|
||||||
foldl' mergeAttrs {} (mapAttrsToList (name: config-f { device = name; }) x.content);
|
foldl' mergeAttrs {} (mapAttrsToList (name: body.config { device = "/dev/${name}"; }) x.content);
|
||||||
|
|
||||||
config.luks = q: x: {
|
config.luks = q: x: {
|
||||||
boot.initrd.luks.devices.${x.name}.device = q.device;
|
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.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:
|
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.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:
|
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: ''
|
create.filesystem = q: x: ''
|
||||||
mkfs.${x.format} ${q.device}
|
mkfs.${x.format} ${q.device}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
create.layout = q: x: ''
|
create.devices = q: x: ''
|
||||||
${concatStrings (mapAttrsToList (name: create-f { device = name; }) x.content)}
|
${concatStrings (mapAttrsToList (name: body.create { device = "/dev/${name}"; }) x.content)}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
create.luks = q: x: ''
|
create.luks = q: x: ''
|
||||||
cryptsetup -q luksFormat ${q.device} ${x.keyfile}
|
cryptsetup -q luksFormat ${q.device} ${x.keyfile}
|
||||||
cryptsetup luksOpen ${q.device} ${x.name} --key-file ${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: ''
|
create.lv = q: x: ''
|
||||||
lvcreate -L ${x.size} -n ${q.name} ${q.vgname}
|
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: ''
|
create.lvm = q: x: ''
|
||||||
pvcreate ${q.device}
|
pvcreate ${q.device}
|
||||||
vgcreate ${x.name} ${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: ''
|
create.partition = q: x: ''
|
||||||
@ -64,16 +64,11 @@ let
|
|||||||
${optionalString (x.bootable or false) ''
|
${optionalString (x.bootable or false) ''
|
||||||
parted -s ${q.device} set ${toString q.index} boot on
|
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: ''
|
create.table = q: x: ''
|
||||||
parted -s ${q.device} mklabel ${x.format}
|
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; };
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user