server-configuration/disko.nix

130 lines
3 KiB
Nix

{ lib
, root-disk ? throw "Expected a mf disk brother"
, raid-disks ? []
, swap-size ? -1
, ...
}: {
disko.devices = {
disk =
{
main = {
type = "disk";
device = root-disk;
content = {
type = "gpt";
partitions = {
boot = {
size = "512M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
swap = lib.mkIf (swap-size != -1) {
size = swap-size;
content = {
type = "swap";
discardPolicy = "both";
resumeDevice = true;
};
};
root = {
size = "100%";
content = {
type = "zfs";
pool = "zroot";
};
};
};
};
};
# disk2 = {
# type = "disk";
# device = "/dev/my-disk2";
# content = {
# type = "gpt";
# partitions = {
# boot = {
# size = "1M";
# type = "EF02"; # for grub MBR
# };
# mdadm = {
# size = "100%";
# content = {
# type = "mdraid";
# name = "raid1";
# };
# };
# };
# };
# };
}
# Import all disks into raid named "raid5"
// lib.attrsets.genAttrs raid-disks (name: {
type = "disk";
device = "/dev/" + name;
content = {
type = "gpt";
partitions = {
zfs = {
size = "100%";
content = {
type = "zfs";
pool = "raid5";
};
};
};
};
});
zpool = {
zroot = {
type = "zpool";
rootFsOptions.mountpoint = "none";
datasets = {
root = {
type = "zfs_fs";
mountpoint = "/";
};
"nix/store" = {
type = "zfs_fs";
mountpoint = "/nix/store";
};
};
};
raid5 = lib.mkIf (builtins.length raid-disks > 0) {
type = "zpool";
mode = "raidz";
rootFsOptions.compression = "zstd";
rootFsOptions.mountpoint = "none";
datasets = {
var = {
type = "zfs_fs";
mountpoint = "/var";
};
home = {
type = "zfs_fs";
mountpoint = "/home";
};
src = {
type = "zfs_fs";
mountpoint = "/srv";
};
opt = {
type = "zfs_fs";
mountpoint = "/opt";
};
};
};
};
};
}