disko/lib/default.nix

75 lines
2.2 KiB
Nix
Raw Normal View History

2018-07-17 19:16:00 +02:00
with import <nixpkgs/lib>;
with builtins;
2018-07-25 01:25:04 +02:00
let {
body.config = q: x: config.${x.type} q x;
body.create = q: x: create.${x.type} q x;
2018-07-17 19:16:00 +02:00
config.filesystem = q: x: {
fileSystems.${x.mountpoint} = {
device = q.device;
fsType = x.format;
};
};
2018-07-25 01:25:04 +02:00
config.devices = q: x:
foldl' mergeAttrs {} (mapAttrsToList (name: body.config { device = "/dev/${name}"; }) x.content);
2018-07-19 21:52:11 +02:00
config.luks = q: x: {
boot.initrd.luks.devices.${x.name}.device = q.device;
2018-07-25 01:25:04 +02:00
} // body.config { device = "/dev/mapper/${x.name}"; } x.content;
2018-07-24 18:53:51 +02:00
config.lv = q: x:
2018-07-25 01:25:04 +02:00
body.config { device = "/dev/${q.vgname}/${q.name}"; } x.content;
2018-07-24 18:53:51 +02:00
config.lvm = q: x:
2018-07-25 01:25:04 +02:00
foldl' mergeAttrs {} (mapAttrsToList (name: body.config { inherit name; vgname = x.name; }) x.lvs);
config.partition = q: x:
2018-07-25 01:25:04 +02:00
body.config { device = q.device + toString q.index; } x.content;
config.table = q: x:
2018-07-25 01:25:04 +02:00
foldl' mergeAttrs {} (imap (index: body.config (q // { inherit index; })) x.partitions);
2018-07-24 18:53:51 +02:00
create.filesystem = q: x: ''
2018-07-17 19:16:00 +02:00
mkfs.${x.format} ${q.device}
'';
2018-07-25 01:25:04 +02:00
create.devices = q: x: ''
${concatStrings (mapAttrsToList (name: body.create { device = "/dev/${name}"; }) x.content)}
2018-07-19 21:52:11 +02:00
'';
2018-07-24 18:53:51 +02:00
create.luks = q: x: ''
cryptsetup -q luksFormat ${q.device} ${x.keyfile}
cryptsetup luksOpen ${q.device} ${x.name} --key-file ${x.keyfile}
2018-07-25 01:25:04 +02:00
${body.create { device = "/dev/mapper/${x.name}"; } x.content}
2018-07-24 18:53:51 +02:00
'';
create.lv = q: x: ''
lvcreate -L ${x.size} -n ${q.name} ${q.vgname}
2018-07-25 01:25:04 +02:00
${body.create { device = "/dev/${q.vgname}/${q.name}"; } x.content}
2018-07-17 19:16:00 +02:00
'';
2018-07-24 18:53:51 +02:00
create.lvm = q: x: ''
2018-07-17 19:16:00 +02:00
pvcreate ${q.device}
vgcreate ${x.name} ${q.device}
2018-07-25 01:25:04 +02:00
${concatStrings (mapAttrsToList (name: body.create { inherit name; vgname = x.name; }) x.lvs)}
2018-07-17 19:16:00 +02:00
'';
2018-07-24 18:53:51 +02:00
create.partition = q: x: ''
2018-07-17 19:16:00 +02:00
parted -s ${q.device} mkpart ${x.part-type} ${x.fs-type or ""} ${x.start} ${x.end}
${optionalString (x.bootable or false) ''
parted -s ${q.device} set ${toString q.index} boot on
''}
2018-07-25 01:25:04 +02:00
${body.create { device = q.device + toString q.index; } x.content}
2018-07-17 19:16:00 +02:00
'';
2018-07-24 18:53:51 +02:00
create.table = q: x: ''
2018-07-17 19:47:27 +02:00
parted -s ${q.device} mklabel ${x.format}
2018-07-25 01:25:04 +02:00
${concatStrings (imap (index: body.create (q // { inherit index; })) x.partitions)}
2018-07-17 19:16:00 +02:00
'';