1
0
Fork 0

Modules: add optional subvolumes parameter to filesystems

This commit is contained in:
Aires 2024-07-03 11:33:28 -04:00
parent 73c9338b88
commit 3a1bc51b68

View file

@ -2,11 +2,7 @@
let let
cfg = config.aux.system.filesystem.btrfs; cfg = config.aux.system.filesystem.btrfs;
standardMountOpts = [ standardMountOpts = [ "compress=zstd" ];
"compress=zstd"
"discard=async"
"noatime"
];
in in
{ {
options = { options = {
@ -24,6 +20,16 @@ in
default = ""; default = "";
}; };
}; };
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"
];
};
swapFile = { swapFile = {
enable = lib.mkEnableOption (lib.mdDoc "Enables the creation of a swap file."); enable = lib.mkEnableOption (lib.mdDoc "Enables the creation of a swap file.");
size = lib.mkOption { size = lib.mkOption {
@ -50,36 +56,52 @@ in
]; ];
fileSystems = fileSystems =
{ {
"/" = { "/" = lib.mkIf (builtins.elem "/" cfg.subvolumes) {
device = cfg.devices.btrfs; device = cfg.devices.btrfs;
fsType = "btrfs"; fsType = "btrfs";
options = [ "subvol=@" ] ++ standardMountOpts; options = [
"subvol=@"
"compress=zstd"
];
}; };
"/boot" = { "/boot" = {
device = cfg.devices.boot; device = cfg.devices.boot;
fsType = "vfat"; fsType = "vfat";
}; };
"/home" = { "/home" = lib.mkIf (builtins.elem "/home" cfg.subvolumes) {
device = cfg.devices.btrfs; device = cfg.devices.btrfs;
fsType = "btrfs"; fsType = "btrfs";
options = [ "subvol=@home" ] ++ standardMountOpts; options = [
"subvol=@home"
"compress=zstd"
];
}; };
"/var/log" = { "/var/log" = lib.mkIf (builtins.elem "/var/log" cfg.subvolumes) {
device = cfg.devices.btrfs; device = cfg.devices.btrfs;
fsType = "btrfs"; fsType = "btrfs";
options = [ "subvol=@log" ] ++ standardMountOpts; options = [
"subvol=@log"
"compress=zstd"
];
}; };
"/nix" = { "/nix" = lib.mkIf (builtins.elem "/nix" cfg.subvolumes) {
device = cfg.devices.btrfs; device = cfg.devices.btrfs;
fsType = "btrfs"; fsType = "btrfs";
options = [ "subvol=@nix" ] ++ standardMountOpts; options = [
"subvol=@nix"
"compress=zstd"
"noatime"
];
}; };
} }
// lib.optionalAttrs cfg.swapFile.enable { // lib.optionalAttrs cfg.swapFile.enable {
"/swap" = { "/swap" = {
device = cfg.devices.btrfs; device = cfg.devices.btrfs;
fsType = "btrfs"; fsType = "btrfs";
options = [ "subvol=@swap" ]; options = [
"subvol=@swap"
"noatime"
];
}; };
}; };