nix-config/disko/disko-config.nix

142 lines
3.8 KiB
Nix

{ lib
, name ? "chaos"
, disk ? "/dev/sda1"
, ...
}:
# TODO:
# option no zfs
# option no ceph
# option no lvm, only zfs
{
disko.devices = {
disk.${disk} = {
device = disk;
type = "disk";
content = {
type = "table";
format = "gpt";
partitions = [
{
name = "ESP";
start = "1MiB";
end = "512MiB";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
name = "root";
start = "512MiB";
end = "100%";
part-type = "primary";
content = {
type = "luks";
name = "crypt-${name}";
# TODO: add password, otherwise prompt opens
keyFile = "/$PWD/keyFile";
content = {
type = "lvm_pv";
vg = "lvm-${name}";
};
};
}
];
};
};
lvm_vg."lvm-${name}" = {
type = "lvm_vg";
lvs =
let
rootSize = 200;
in
{
# the header is 3650 byte long and substract an additional 446 byte for aligment
# error messages:
# Volume group "lvm-chaos" has insufficient free space (51195 extents): 51200 required.
# Size is not a multiple of 512. Try using 40057405440 or 40057405952.
raw.size =
let
# convert GiB to bytes
rootSizeMiB = rootSize * 1024 * 1024 * 1024;
# convert back to MiB and allign to 4 MiB in the process
roundToMiB = "/1024/1024/4*4";
# substract 512 MiB for /boot and 20 MiB for luks+header+other
bootOther = "-512-20";
in
"$((($(lsblk /dev/sda --noheadings --nodeps --output SIZE --bytes)-${toString rootSizeMiB})${roundToMiB}${bootOther}))MiB";
zfs = {
size = "${toString rootSize}GiB";
content = {
pool = name;
type = "zfs";
};
};
};
};
zpool."${name}" = {
type = "zpool";
rootFsOptions.acltype = "posixacl";
options = {
ashift = "12";
autotrim = "on";
};
datasets =
let
dataset = mountpoint: {
options = {
canmount = "on";
compression = "zstd";
normalization = "formD";
xattr = "sa";
inherit mountpoint;
};
type = "zfs_fs";
};
in
{
"data" = dataset "/";
"data/etc" = dataset "/etc";
"data/home" = dataset "/home";
"data/var" = dataset "/var";
# used by services.postgresqlBackup and later by restic
"data/var/backup" = dataset "/var/backup";
"data/var/lib" = dataset "/var/lib";
"data/var/log" = dataset "/var/log";
"nixos" = {
options = {
canmount = "off";
mountpoint = "none";
};
type = "zfs_fs";
};
"nixos/nix" = dataset "/nix";
"nixos/nix/store" = {
options = {
atime = "off";
canmount = "on";
mountpoint = "/nix/store";
};
type = "zfs_fs";
};
"nixos/nix/var" = dataset "/nix/var";
"resered" = {
# zfs uses copy on write and requires some free space to delete files when the disk is completely filled
options = {
canmount = "off";
mountpoint = "none";
reservation = "5GiB";
};
type = "zfs_fs";
};
};
};
};
}