nixos-servers/nixos/modules/storage.nix

81 lines
1.8 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 {
type = lib.types.str;
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.
'';
};
};
2024-02-27 22:28:52 +00:00
config = {
fileSystems = lib.attrsets.mergeAttrsList [
(lib.optionalAttrs machine.isHypervisor {
"${cfg.dataMountPoint}".device = cfg.dataPartition;
})
(lib.optionalAttrs machine.isRaspberryPi {
"/" = {
device = "/dev/disk/by-label/NIXOS_SD";
fsType = "ext4";
options = [ "noatime" ];
};
})
];
2024-01-06 23:22:44 +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
disko = lib.mkIf machine.isHypervisor {
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
};
};
};
};
};
};
}