nixos-servers/nixos-modules/storage.nix

189 lines
4.2 KiB
Nix
Raw Normal View History

2024-01-28 10:48:13 +00:00
{ lib, config, machine, ... }:
2024-01-06 23:22:44 +00:00
let cfg = config.lab.storage;
in {
options.lab.storage = {
osDisk = lib.mkOption {
2024-02-29 19:59:48 +00:00
type = with lib.types; nullOr str;
2024-01-06 23:22:44 +00:00
description = ''
The disk to be used for the machine's operating system.
'';
};
dataPartition = lib.mkOption {
2024-02-26 22:08:12 +00:00
default = null;
type = lib.types.nullOr lib.types.str;
2024-01-06 23:22:44 +00:00
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.
'';
};
2024-01-06 23:22:44 +00:00
};
2024-02-27 22:28:52 +00:00
config = {
fileSystems = lib.attrsets.mergeAttrsList [
(lib.optionalAttrs ((! machine.isRaspberryPi) && (! cfg.kubernetesNode)) {
"${cfg.dataMountPoint}".device = cfg.dataPartition;
})
(lib.optionalAttrs 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";
};
};
};
};
2024-02-27 22:28:52 +00:00
};
2024-01-06 23:22:44 +00:00
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 {
2024-02-29 19:59:48 +00:00
# TODO: Rename this to 'osDisk'. Unfortunately, we would need to run nixos-anywhere again then.
2024-02-27 22:28:52 +00:00
devices.disk.vdb = {
device = cfg.osDisk;
type = "disk";
2024-01-06 23:22:44 +00:00
2024-02-27 22:28:52 +00:00
content = {
type = "gpt";
2024-01-06 23:22:44 +00:00
2024-02-27 22:28:52 +00:00
partitions = {
swap.size = "100%";
2024-01-06 23:22:44 +00:00
2024-02-27 22:28:52 +00:00
ESP = {
type = "EF00";
size = "500M";
2024-01-06 23:22:44 +00:00
2024-02-27 22:28:52 +00:00
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
2024-01-06 23:22:44 +00:00
};
2024-02-27 22:28:52 +00:00
root = {
end = "-4G";
2024-01-06 23:22:44 +00:00
2024-02-27 22:28:52 +00:00
content = {
type = "filesystem";
format = "btrfs";
mountpoint = "/";
};
2024-01-06 23:22:44 +00:00
};
};
};
};
});
2024-01-06 23:22:44 +00:00
};
}