{ lib, config, machine, ... }: let cfg = config.lab.storage; in { options.lab.storage = { osDisk = lib.mkOption { type = with lib.types; nullOr str; description = '' The disk to be used for the machine's operating system. ''; }; dataPartition = lib.mkOption { default = null; type = lib.types.nullOr lib.types.str; description = '' Partition to be used for data storage on this machine. ''; }; dataMountPoint = lib.mkOption { default = "/mnt/data"; type = lib.types.str; description = '' Mount point of the machine's data partition. ''; }; kubernetesNode = lib.mkOption { default = false; type = lib.types.bool; description = '' Whether to apply the Kubernetes disk setup. ''; }; }; config = { fileSystems = { "/" = lib.mkIf machine.isRaspberryPi { device = "/dev/disk/by-label/NIXOS_SD"; fsType = "ext4"; options = [ "noatime" ]; }; }; disko = lib.mkIf (! machine.isRaspberryPi) (if cfg.kubernetesNode then { devices = { disk = { nvme = { device = "/dev/nvme0n1"; type = "disk"; content = { type = "gpt"; partitions = { boot = { type = "EF00"; size = "500M"; content = { type = "filesystem"; format = "vfat"; mountpoint = "/boot"; }; }; pv_os = { size = "79G"; content = { type = "lvm_pv"; vg = "vg_os"; }; }; pv_nvme_extra = { size = "100%"; content = { type = "lvm_pv"; vg = "vg_data"; }; }; }; }; }; sata = { device = "/dev/sda"; type = "disk"; content = { type = "gpt"; partitions.pv_sata = { size = "100%"; content = { type = "lvm_pv"; vg = "vg_data"; }; }; }; }; }; lvm_vg = { vg_os = { type = "lvm_vg"; lvs = { root = { size = "75G"; content = { type = "filesystem"; format = "ext4"; mountpoint = "/"; mountOptions = [ "defaults" ]; }; }; swap = { size = "100%FREE"; content.type = "swap"; }; }; }; vg_data = { type = "lvm_vg"; lvs.longhorn = { size = "100%FREE"; content = { type = "filesystem"; format = "xfs"; mountpoint = "/mnt/longhorn"; }; }; }; }; }; } else { # TODO: Rename this to 'osDisk'. Unfortunately, we would need to run nixos-anywhere again then. devices.disk.vdb = { device = cfg.osDisk; type = "disk"; content = { type = "gpt"; partitions = { swap.size = "100%"; ESP = { type = "EF00"; size = "500M"; content = { type = "filesystem"; format = "vfat"; mountpoint = "/boot"; }; }; root = { end = "-4G"; content = { type = "filesystem"; format = "btrfs"; mountpoint = "/"; }; }; }; }; }; }); }; }