2024-06-28 20:06:23 +00:00
|
|
|
{ lib, config, ... }:
|
|
|
|
let
|
2024-07-01 13:48:14 +00:00
|
|
|
cfg = config.aux.system.disko;
|
2024-06-28 20:06:23 +00:00
|
|
|
|
|
|
|
standardMountOpts = [
|
|
|
|
"compress=zstd"
|
|
|
|
"noatime"
|
|
|
|
];
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2024-07-01 13:48:14 +00:00
|
|
|
aux.system.disko = {
|
2024-06-28 20:06:23 +00:00
|
|
|
enable = lib.mkEnableOption (lib.mdDoc "Enables Disko for disk & partition management.");
|
2024-07-01 13:48:14 +00:00
|
|
|
primaryDiskID = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The ID of the disk to manage using Disko. If possible, use the World Wide Name (WWN), e.g `/dev/disk/by-id/nvme-eui.*`";
|
|
|
|
default = "";
|
2024-06-28 20:06:23 +00:00
|
|
|
};
|
|
|
|
swapFile = {
|
|
|
|
enable = lib.mkEnableOption (lib.mdDoc "Enables the creation of swap files.");
|
|
|
|
size = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The size of the swap file to create (defaults to 8G, or 8 gigabytes).";
|
|
|
|
default = "8G";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2024-07-01 13:48:14 +00:00
|
|
|
# Check for blank values
|
2024-07-01 16:47:35 +00:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = (cfg.primaryDiskID != "");
|
|
|
|
message = "aux.system.disko.primaryDiskID is not set. Please enter a valid disk ID.";
|
|
|
|
}
|
|
|
|
];
|
2024-06-28 20:06:23 +00:00
|
|
|
# Disk management
|
2024-07-01 13:48:14 +00:00
|
|
|
disko.enableConfig = true;
|
2024-06-28 20:06:23 +00:00
|
|
|
disko.devices = {
|
|
|
|
disk = {
|
|
|
|
main = {
|
|
|
|
type = "disk";
|
2024-07-01 16:47:35 +00:00
|
|
|
device = "/dev/disk/by-id/${cfg.primaryDiskID}";
|
2024-06-28 20:06:23 +00:00
|
|
|
content = {
|
|
|
|
type = "gpt";
|
|
|
|
partitions = {
|
|
|
|
ESP = {
|
|
|
|
priority = 1;
|
|
|
|
name = "ESP";
|
|
|
|
label = "boot";
|
|
|
|
size = "1G";
|
|
|
|
type = "EF00";
|
|
|
|
content = {
|
|
|
|
type = "filesystem";
|
|
|
|
format = "vfat";
|
|
|
|
mountpoint = "/boot";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
luks = {
|
|
|
|
size = "100%";
|
|
|
|
label = "nixos";
|
|
|
|
content = {
|
|
|
|
type = "luks";
|
|
|
|
name = "cryptroot";
|
|
|
|
settings = {
|
|
|
|
allowDiscards = true;
|
2024-07-01 13:48:14 +00:00
|
|
|
crypttabExtraOpts = lib.mkIf config.aux.system.bootloader.tpm2.enable [ "tpm2-device=auto" ];
|
2024-06-28 20:06:23 +00:00
|
|
|
};
|
|
|
|
content = {
|
|
|
|
type = "btrfs";
|
|
|
|
extraArgs = [ "-f" ]; # Override existing partitions.
|
|
|
|
# Unless otherwise specified, the subvolume name equals the mount name.
|
|
|
|
subvolumes = {
|
|
|
|
"/root" = {
|
|
|
|
mountpoint = "/";
|
|
|
|
mountOptions = standardMountOpts;
|
|
|
|
};
|
|
|
|
"/home" = {
|
|
|
|
mountOptions = standardMountOpts;
|
|
|
|
};
|
|
|
|
"/nix" = {
|
|
|
|
mountOptions = standardMountOpts;
|
|
|
|
};
|
|
|
|
"/swap" = lib.mkIf cfg.swapFile.enable {
|
|
|
|
mountpoint = "/.swap";
|
|
|
|
swap.swapfile.size = cfg.swapFile.size;
|
|
|
|
};
|
|
|
|
"/log" = {
|
|
|
|
mountpoint = "/var/log";
|
|
|
|
mountOptions = standardMountOpts;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|