Files

102 lines
3.1 KiB
Nix

# roles/thin-client/deployment/disko.nix
#
# BTRFS disk layout via Disko. Used by `nixos-anywhere` during provisioning.
# Q4 decisions: Standard persistent BTRFS, subvolumes @root and @home,
# zstd compression, snapper for / (NOT /home — privacy for multi-user).
#
# Apply during provisioning:
# nixos-anywhere --flake .#AZ-TC-01 \
# --disko disko-config ./roles/thin-client/deployment/disko.nix \
# root@<target-ip>
#
# This module sets `disko.devices` so the config can be referenced both
# for partitioning (nixos-anywhere --disko) and for fstab generation.
{
config,
lib,
...
}: let
inherit (lib) mkIf mkOption types;
cfg = config.az.tc;
in {
options.az.tc.deployment = {
diskDevice = mkOption {
type = types.str;
default = "/dev/sda";
description = ''
Target disk device for the BTRFS layout. Typically /dev/sda or
/dev/nvme0n1. Override per-host in hosts/AZ-TC-NN/default.nix.
'';
};
swapSizeGB = mkOption {
type = types.int;
default = 4;
description = "Swap partition size in GB. Set 0 to disable swap.";
};
};
config = mkIf cfg.enable {
disko.devices = {
disk.main = {
type = "disk";
device = config.az.tc.deployment.diskDevice;
# Disko's VM test defaults to a 2 GiB image. That cannot contain
# our 512 MiB ESP, 4 GiB swap and BTRFS root partition.
imageSize = "8G";
content = {
type = "gpt";
partitions = {
ESP = {
size = "512M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = ["umask=0077"];
};
};
swap = mkIf (config.az.tc.deployment.swapSizeGB > 0) {
size = "${toString config.az.tc.deployment.swapSizeGB}G";
content = {
type = "swap";
randomEncryption = true;
};
};
root = {
size = "100%";
content = {
type = "btrfs";
extraArgs = ["-f"]; # force overwrite
subvolumes = {
"@root" = {
mountpoint = "/";
mountOptions = ["compress=zstd" "noatime" "ssd"];
};
"@home" = {
mountpoint = "/home";
mountOptions = ["compress=zstd" "noatime" "ssd"];
};
"@nix" = {
mountpoint = "/nix";
mountOptions = ["compress=zstd" "noatime" "ssd"];
};
"@persist" = {
mountpoint = "/persist";
mountOptions = ["compress=zstd" "noatime" "ssd"];
};
"@snapshots" = {
mountpoint = "/.snapshots";
mountOptions = ["compress=zstd" "noatime" "ssd"];
};
};
};
};
};
};
};
};
};
}