2024-07-02 22:15:37 +00:00
|
|
|
{ lib, config, ... }:
|
|
|
|
let
|
2024-07-04 01:13:13 +00:00
|
|
|
cfg = config.aux.system.filesystem;
|
2024-07-02 22:15:37 +00:00
|
|
|
|
2024-07-05 13:36:11 +00:00
|
|
|
# LUKS partition will decrypt to /dev/mapper/nixos-root
|
|
|
|
decryptPart = "nixos-root";
|
|
|
|
decryptPath = "/dev/mapper/${decryptPart}";
|
2024-07-02 22:15:37 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2024-07-04 01:13:13 +00:00
|
|
|
aux.system.filesystem = {
|
2024-07-05 13:36:11 +00:00
|
|
|
enable = lib.mkEnableOption (lib.mdDoc "Enables standard BTRFS subvolumes and parameters.");
|
|
|
|
partitions = {
|
|
|
|
boot = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The ID of your boot partition. Use /dev/disk/by-uuid for best results.";
|
|
|
|
default = "";
|
2024-07-02 22:15:37 +00:00
|
|
|
};
|
2024-07-05 13:36:11 +00:00
|
|
|
luks = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The ID of your LUKS partition. Use /dev/disk/by-uuid for best results.";
|
|
|
|
default = "";
|
2024-07-02 22:15:37 +00:00
|
|
|
};
|
|
|
|
};
|
2024-07-05 13:36:11 +00:00
|
|
|
swapFile = {
|
|
|
|
enable = lib.mkEnableOption (lib.mdDoc "Enables the creation of a swap file.");
|
|
|
|
size = lib.mkOption {
|
|
|
|
type = lib.types.int;
|
|
|
|
description = "The size of the swap file to create in MB (defaults to 8192, or ~8 gigabytes).";
|
|
|
|
default = 8192;
|
2024-07-02 22:15:37 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-07-05 13:36:11 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2024-07-02 22:15:37 +00:00
|
|
|
|
|
|
|
# Check for blank parameters
|
|
|
|
assertions = [
|
|
|
|
{
|
2024-07-05 13:36:11 +00:00
|
|
|
assertion = cfg.partitions.luks != "";
|
|
|
|
message = "Please specify a LUKS partition to use as the root filesystem.";
|
2024-07-02 22:15:37 +00:00
|
|
|
}
|
|
|
|
{
|
2024-07-05 13:36:11 +00:00
|
|
|
assertion = cfg.partitions.boot != "";
|
|
|
|
message = "Please specify your boot partition.";
|
2024-07-02 22:15:37 +00:00
|
|
|
}
|
|
|
|
];
|
2024-07-05 13:36:11 +00:00
|
|
|
boot.initrd.luks.devices.${decryptPart} = {
|
|
|
|
device = cfg.partitions.luks;
|
|
|
|
# Enable TPM auto-unlocking if configured
|
|
|
|
crypttabExtraOpts = lib.mkIf config.aux.system.bootloader.tpm2.enable [ "tpm2-device=auto" ];
|
2024-07-04 01:13:13 +00:00
|
|
|
};
|
2024-07-02 22:15:37 +00:00
|
|
|
fileSystems =
|
|
|
|
{
|
2024-07-04 01:13:13 +00:00
|
|
|
"/" = {
|
2024-07-05 13:36:11 +00:00
|
|
|
device = decryptPath;
|
2024-07-02 22:15:37 +00:00
|
|
|
fsType = "btrfs";
|
2024-07-03 15:33:28 +00:00
|
|
|
options = [
|
|
|
|
"subvol=@"
|
|
|
|
"compress=zstd"
|
|
|
|
];
|
2024-07-02 22:15:37 +00:00
|
|
|
};
|
|
|
|
"/boot" = {
|
2024-07-05 13:36:11 +00:00
|
|
|
device = cfg.partitions.boot;
|
2024-07-02 22:15:37 +00:00
|
|
|
fsType = "vfat";
|
|
|
|
};
|
2024-07-04 01:13:13 +00:00
|
|
|
"/home" = {
|
2024-07-05 13:36:11 +00:00
|
|
|
device = decryptPath;
|
2024-07-02 22:15:37 +00:00
|
|
|
fsType = "btrfs";
|
2024-07-03 15:33:28 +00:00
|
|
|
options = [
|
|
|
|
"subvol=@home"
|
|
|
|
"compress=zstd"
|
|
|
|
];
|
2024-07-02 22:15:37 +00:00
|
|
|
};
|
2024-07-04 01:13:13 +00:00
|
|
|
"/var/log" = {
|
2024-07-05 13:36:11 +00:00
|
|
|
device = decryptPath;
|
2024-07-02 22:15:37 +00:00
|
|
|
fsType = "btrfs";
|
2024-07-03 15:33:28 +00:00
|
|
|
options = [
|
|
|
|
"subvol=@log"
|
|
|
|
"compress=zstd"
|
|
|
|
];
|
2024-07-02 22:15:37 +00:00
|
|
|
};
|
2024-07-04 01:13:13 +00:00
|
|
|
"/nix" = {
|
2024-07-05 13:36:11 +00:00
|
|
|
device = decryptPath;
|
2024-07-02 22:15:37 +00:00
|
|
|
fsType = "btrfs";
|
2024-07-03 15:33:28 +00:00
|
|
|
options = [
|
|
|
|
"subvol=@nix"
|
|
|
|
"compress=zstd"
|
|
|
|
"noatime"
|
|
|
|
];
|
2024-07-02 22:15:37 +00:00
|
|
|
};
|
|
|
|
}
|
2024-07-05 13:36:11 +00:00
|
|
|
// lib.optionalAttrs cfg.swapFile.enable {
|
2024-07-02 22:15:37 +00:00
|
|
|
"/swap" = {
|
2024-07-05 13:36:11 +00:00
|
|
|
device = decryptPath;
|
2024-07-02 22:15:37 +00:00
|
|
|
fsType = "btrfs";
|
2024-07-03 15:33:28 +00:00
|
|
|
options = [
|
|
|
|
"subvol=@swap"
|
|
|
|
"noatime"
|
|
|
|
];
|
2024-07-02 22:15:37 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-07-05 13:36:11 +00:00
|
|
|
swapDevices = lib.mkIf cfg.swapFile.enable [
|
2024-07-02 22:15:37 +00:00
|
|
|
{
|
|
|
|
device = "/swap/swapfile";
|
2024-07-05 13:36:11 +00:00
|
|
|
size = cfg.swapFile.size;
|
2024-07-02 22:15:37 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|