reimplement disko using the nixos type system

This should make the code cleaner, more robust and errors should be
clearer. we also changed the configuration format a bit.
This commit is contained in:
lassulus 2022-08-29 11:45:19 +02:00
parent adf901d581
commit dcb0c42857
11 changed files with 1545 additions and 534 deletions

View file

@ -1,25 +1,28 @@
{
type = "devices";
content = {
disk = {
vdb = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
part-type = "primary";
start = "0%";
end = "100%";
content = {
type = "btrfs";
mountpoint = "/";
subvolumes = [
"/home"
"/test"
];
};
}
];
type = "disk";
device = "/dev/vdb";
content = {
type = "table";
format = "gpt";
partitions = [
{
name = "root";
type = "partition";
start = "0%";
end = "100%";
content = {
type = "btrfs";
mountpoint = "/";
subvolumes = [
"/home"
"/test"
];
};
}
];
};
};
};
}

194
example/complex.nix Normal file
View file

@ -0,0 +1,194 @@
{
disk = {
disk1 = {
type = "disk";
device = "/dev/vdb";
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
start = "0";
end = "1M";
name = "grub";
flags = ["bios_grub"];
}
{
type = "partition";
start = "1M";
end = "100%";
name = "luks";
bootable = true;
content = {
type = "luks";
name = "crypted1";
keyFile = "/tmp/secret.key";
extraArgs = [
"--hash sha512"
"--iter-time 5000"
];
content = {
type = "lvm_pv";
vg = "pool";
};
};
}
];
};
};
disk2 = {
type = "disk";
device = "/dev/vdc";
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
start = "0";
end = "1M";
name = "grub";
flags = ["bios_grub"];
}
{
type = "partition";
start = "1M";
end = "100%";
name = "luks";
bootable = true;
content = {
type = "luks";
name = "crypted2";
keyFile = "/tmp/secret.key";
extraArgs = [
"--hash sha512"
"--iter-time 5000"
];
content = {
type = "lvm_pv";
vg = "pool";
};
};
}
];
};
};
};
mdadm = {
raid1 = {
type = "mdadm";
level = 1;
content = {
type = "table";
format = "msdos";
partitions = [
{
type = "partition";
name = "xfs";
start = "1MiB";
end = "100%";
content = {
type = "filesystem";
format = "xfs";
mountpoint = "/xfs_mdadm_lvm";
};
}
];
};
};
};
lvm_vg = {
pool = {
type = "lvm_vg";
lvs = {
root = {
type = "lvm_lv";
size = "10M";
lvm_type = "mirror";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/ext4_on_lvm";
options = [
"defaults"
];
};
};
raid1 = {
type = "lvm_lv";
size = "30M";
lvm_type = "raid0";
content = {
type = "mdraid";
name = "raid1";
};
};
raid2 = {
type = "lvm_lv";
size = "30M";
lvm_type = "raid0";
content = {
type = "mdraid";
name = "raid1";
};
};
zfs1 = {
type = "lvm_lv";
size = "128M";
lvm_type = "raid0";
content = {
type = "zfs";
pool = "zroot";
};
};
zfs2 = {
type = "lvm_lv";
size = "128M";
lvm_type = "raid0";
content = {
type = "zfs";
pool = "zroot";
};
};
};
};
};
zpool = {
zroot = {
type = "zpool";
mode = "mirror";
rootFsOptions = {
compression = "lz4";
"com.sun:auto-snapshot" = "false";
};
mountpoint = "/";
datasets = {
zfs_fs = {
zfs_type = "filesystem";
mountpoint = "/zfs_fs";
options."com.sun:auto-snapshot" = "true";
};
zfs_unmounted_fs = {
zfs_type = "filesystem";
options.mountpoint = "none";
};
zfs_legacy_fs = {
zfs_type = "filesystem";
options.mountpoint = "legacy";
mountpoint = "/zfs_legacy_fs";
};
zfs_testvolume = {
zfs_type = "volume";
size = "10M";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/ext4onzfs";
};
};
};
};
};
}

View file

@ -1,81 +1,81 @@
{
type = "devices";
content = {
disk = {
vdb = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
part-type = "ESP";
start = "1MiB";
end = "100MiB";
fs-type = "FAT32";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
options = [
"defaults"
];
};
}
{
type = "partition";
part-type = "primary";
start = "100MiB";
end = "100%";
content = {
type = "luks";
algo = "aes-xts...";
name = "crypted";
keyfile = "/tmp/secret.key";
extraArgs = [
"--hash sha512"
"--iter-time 5000"
];
content = {
type = "lvm_pv";
vg = "pool";
};
};
}
];
};
pool = {
type = "lvm_vg";
lvs = {
root = {
type = "lvm_lv";
size = "100M";
mountpoint = "/";
type = "disk";
device = "/dev/vdb";
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
# fs-type = "FAT32";
start = "1MiB";
end = "100MiB";
bootable = true;
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
format = "vfat";
mountpoint = "/boot";
options = [
"defaults"
];
};
};
home = {
type = "lvm_lv";
size = "10M";
}
{
type = "partition";
name = "luks";
start = "100MiB";
end = "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/home";
};
};
raw = {
type = "lvm_lv";
size = "10M";
content = {
type = "noop";
type = "luks";
name = "crypted";
keyFile = "/tmp/secret.key";
extraArgs = [
"--hash sha512"
"--iter-time 5000"
];
content = {
type = "lvm_pv";
vg = "pool";
};
};
}
];
};
};
};
lvm_vg = {
pool = {
type = "lvm_vg";
lvs = {
root = {
type = "lvm_lv";
size = "100M";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
options = [
"defaults"
];
};
};
home = {
type = "lvm_lv";
size = "10M";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/home";
};
};
raw = {
type = "lvm_lv";
size = "10M";
};
};
};
};
}

View file

@ -1,66 +1,74 @@
{
type = "devices";
content = {
disk = {
vdb = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
part-type = "primary";
start = "0%";
end = "100%";
content = {
type = "lvm_pv";
vg = "pool";
};
}
];
type = "disk";
device = "/dev/vdb";
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "primary";
start = "0%";
end = "100%";
content = {
type = "lvm_pv";
vg = "pool";
};
}
];
};
};
vdc = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
part-type = "primary";
start = "0%";
end = "100%";
content = {
type = "lvm_pv";
vg = "pool";
};
}
];
type = "disk";
device = "/dev/vdc";
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "primary";
start = "0%";
end = "100%";
content = {
type = "lvm_pv";
vg = "pool";
};
}
];
};
};
};
lvm_vg = {
pool = {
type = "lvm_vg";
lvs = {
root = {
type = "lvm_lv";
size = "100M";
lvs = {
root = {
type = "lvm_lv";
size = "100M";
lvm_type = "mirror";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
lvm_type = "mirror";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
options = [
"defaults"
];
};
};
home = {
type = "lvm_lv";
size = "10M";
lvm_type = "raid0";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/home";
};
options = [
"defaults"
];
};
};
home = {
type = "lvm_lv";
size = "10M";
lvm_type = "raid0";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/home";
};
};
};
};
};
}

View file

@ -1,39 +1,47 @@
# usage: nix-instantiate --eval --json --strict example/config.nix | jq .
{
type = "devices";
content = {
disk = {
vdb = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
part-type = "primary";
start = "1MiB";
end = "100%";
content = {
type = "mdraid";
name = "raid1";
};
}
];
type = "disk";
device = "/dev/vdb";
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "mdadm";
start = "1MiB";
end = "100%";
content = {
type = "mdraid";
name = "raid1";
};
}
];
};
};
vdc = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
part-type = "primary";
start = "1MiB";
end = "100%";
content = {
type = "mdraid";
name = "raid1";
};
}
];
type = "disk";
device = "/dev/vdc";
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
name = "mdadm";
start = "1MiB";
end = "100%";
content = {
type = "mdraid";
name = "raid1";
};
}
];
};
};
};
mdadm = {
raid1 = {
type = "mdadm";
level = 1;
@ -43,7 +51,7 @@
partitions = [
{
type = "partition";
part-type = "primary";
name = "primary";
start = "1MiB";
end = "100%";
content = {

View file

@ -1,41 +1,46 @@
{
type = "devices";
content = {
disk = {
vdb = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
# leave space for the grub aka BIOS boot
start = "0%";
end = "100%";
part-type = "primary";
bootable = true;
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
}
];
type = "disk";
device = "/dev/vdb";
content = {
type = "table";
format = "gpt";
partitions = [
{
type = "partition";
start = "0%";
end = "100%";
name = "primary";
bootable = true;
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
}
];
};
};
vdc = {
type = "zfs";
pool = "zroot";
type = "disk";
device = "/dev/vdc";
content = {
type = "zfs";
pool = "zroot";
};
};
};
zpool = {
zroot = {
type = "zpool";
mountpoint = "/";
datasets = [
{
type = "zfs_filesystem";
name = "zfs_fs";
datasets = {
zfs_fs = {
zfs_type = "filesystem";
mountpoint = "/zfs_fs";
options."com.sun:auto-snapshot" = "true";
}
];
};
};
};
};
}

View file

@ -1,14 +1,23 @@
{
type = "devices";
content = {
disk = {
vdb = {
type = "zfs";
pool = "zroot";
type = "disk";
device = "/dev/vdb";
content = {
type = "zfs";
pool = "zroot";
};
};
vdc = {
type = "zfs";
pool = "zroot";
type = "disk";
device = "/dev/vdc";
content = {
type = "zfs";
pool = "zroot";
};
};
};
zpool = {
zroot = {
type = "zpool";
mode = "mirror";
@ -18,35 +27,31 @@
};
mountpoint = "/";
datasets = [
{
type = "zfs_filesystem";
name = "zfs_fs";
datasets = {
zfs_fs = {
zfs_type = "filesystem";
mountpoint = "/zfs_fs";
options."com.sun:auto-snapshot" = "true";
}
{
type = "zfs_filesystem";
name = "zfs_unmounted_fs";
};
zfs_unmounted_fs = {
zfs_type = "filesystem";
options.mountpoint = "none";
}
{
type = "zfs_filesystem";
name = "zfs_legacy_fs";
};
zfs_legacy_fs = {
zfs_type = "filesystem";
options.mountpoint = "legacy";
mountpoint = "/zfs_legacy_fs";
}
{
type = "zfs_volume";
name = "zfs_testvolume";
};
zfs_testvolume = {
zfs_type = "volume";
size = "10M";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/ext4onzfs";
};
}
];
};
};
};
};
}