{ config, lib, ... }: let cfg = config.disko; in { options.disko.disks = lib.mkOption { description = lib.mdDoc "Disk names to format."; type = with lib.types; listOf (submodule (_: { options = { device = lib.mkOption { type = lib.types.str; default = null; example = "/dev/sda"; description = "Path of the disk."; }; name = lib.mkOption { type = lib.types.str; default = null; example = "ssd0"; description = "Name of the disk."; }; withBoot = lib.mkOption { type = lib.types.bool; default = true; description = "Wether to include a boot partition."; }; withCeph = lib.mkOption { type = lib.types.bool; default = true; description = "Wether to include a ceph partition."; }; withLuks = lib.mkOption { type = lib.types.bool; default = true; description = "Wether to encrypt the paritions."; }; withZfs = lib.mkOption { type = lib.types.bool; default = true; description = "Wether to include a zfs parition."; }; }; })); default = [ ]; }; config = { assertions = lib.mkIf (cfg.disks != [ ]) (lib.head (map (disk: [ { assertion = disk.withCeph || disk.withZfs; message = "Must enable ceph or zfs!"; } { assertion = disk.withCeph -> disk.withLuks; message = "Ceph requires Luks!"; } ]) cfg.disks)); disko.devices = lib.mkIf (cfg.disks != [ ]) (lib.head (map (disk: let diskName = if disk.name != "" then "-${disk.name}" else ""; luksName = "crypt-${config.networking.hostName}${diskName}"; rootSize = 200; # size of the zfs partition if inside of lvm vgName = "lvm-${config.networking.hostName}${diskName}"; zfs = { size = if (!disk.withCeph) then "100%FREE" else "${toString rootSize}GiB"; content = { pool = zfsName; type = "zfs"; }; }; zfsName = "${config.networking.hostName}${diskName}"; in { disk.${disk.device} = { inherit (disk) device; type = "disk"; content = { type = "table"; format = "gpt"; partitions = lib.optional disk.withZfs { name = "ESP"; start = "1MiB"; end = "512MiB"; bootable = true; content = { type = "filesystem"; format = "vfat"; mountpoint = "/boot"; }; } ++ [ { name = "root"; start = if disk.withZfs then "512MiB" else "1MiB"; end = "100%"; part-type = "primary"; content = lib.optionalAttrs disk.withLuks { type = "luks"; name = luksName; # trim potential new lines to not have them in the password keyFile = "tr -d '\n'