2024-07-02 22:15:37 +00:00
|
|
|
{ lib, config, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.aux.system.filesystem.btrfs;
|
|
|
|
|
2024-07-03 15:33:28 +00:00
|
|
|
standardMountOpts = [ "compress=zstd" ];
|
2024-07-02 22:15:37 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
aux.system.filesystem.btrfs = {
|
|
|
|
enable = lib.mkEnableOption (lib.mdDoc "Enables standard BTRFS subvolumes and parameters.");
|
|
|
|
devices = {
|
|
|
|
boot = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The ID of your boot partition. Use /dev/disk/by-uuid for best results.";
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
btrfs = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The ID of your BTRFS partition. Use /dev/disk/by-uuid for best results.";
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
};
|
2024-07-03 15:33:28 +00:00
|
|
|
subvolumes = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
description = "Which subvolumes to mount. Leave as the default to create all standard subvolumes.";
|
|
|
|
default = [
|
|
|
|
"/"
|
|
|
|
"/home"
|
|
|
|
"/nix"
|
|
|
|
"/var/log"
|
|
|
|
];
|
|
|
|
};
|
2024-07-02 22:15:37 +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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
|
|
|
|
# Check for blank parameters
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.devices.btrfs != "";
|
|
|
|
message = "Please specify a BTRFS partition to use as a filesystem.";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.devices.boot != "";
|
|
|
|
message = "Please specify a boot partition to use as a filesystem.";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
fileSystems =
|
|
|
|
{
|
2024-07-03 15:33:28 +00:00
|
|
|
"/" = lib.mkIf (builtins.elem "/" cfg.subvolumes) {
|
2024-07-02 22:15:37 +00:00
|
|
|
device = cfg.devices.btrfs;
|
|
|
|
fsType = "btrfs";
|
2024-07-03 15:33:28 +00:00
|
|
|
options = [
|
|
|
|
"subvol=@"
|
|
|
|
"compress=zstd"
|
|
|
|
];
|
2024-07-02 22:15:37 +00:00
|
|
|
};
|
|
|
|
"/boot" = {
|
|
|
|
device = cfg.devices.boot;
|
|
|
|
fsType = "vfat";
|
|
|
|
};
|
2024-07-03 15:33:28 +00:00
|
|
|
"/home" = lib.mkIf (builtins.elem "/home" cfg.subvolumes) {
|
2024-07-02 22:15:37 +00:00
|
|
|
device = cfg.devices.btrfs;
|
|
|
|
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-03 15:33:28 +00:00
|
|
|
"/var/log" = lib.mkIf (builtins.elem "/var/log" cfg.subvolumes) {
|
2024-07-02 22:15:37 +00:00
|
|
|
device = cfg.devices.btrfs;
|
|
|
|
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-03 15:33:28 +00:00
|
|
|
"/nix" = lib.mkIf (builtins.elem "/nix" cfg.subvolumes) {
|
2024-07-02 22:15:37 +00:00
|
|
|
device = cfg.devices.btrfs;
|
|
|
|
fsType = "btrfs";
|
2024-07-03 15:33:28 +00:00
|
|
|
options = [
|
|
|
|
"subvol=@nix"
|
|
|
|
"compress=zstd"
|
|
|
|
"noatime"
|
|
|
|
];
|
2024-07-02 22:15:37 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
// lib.optionalAttrs cfg.swapFile.enable {
|
|
|
|
"/swap" = {
|
|
|
|
device = cfg.devices.btrfs;
|
|
|
|
fsType = "btrfs";
|
2024-07-03 15:33:28 +00:00
|
|
|
options = [
|
|
|
|
"subvol=@swap"
|
|
|
|
"noatime"
|
|
|
|
];
|
2024-07-02 22:15:37 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
swapDevices = lib.mkIf cfg.swapFile.enable [
|
|
|
|
{
|
|
|
|
device = "/swap/swapfile";
|
|
|
|
size = cfg.swapFile.size;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|