config/modules/base/fileSystems/default.nix

84 lines
1.9 KiB
Nix
Raw Normal View History

2024-07-29 15:39:54 +03:00
{ config, lib, ... }:
let
2023-07-22 16:05:44 +03:00
cfg = config.zfs-root.fileSystems;
2024-07-29 15:39:54 +03:00
inherit (lib)
types
mkDefault
mkOption
mkMerge
mapAttrsToList
;
in
{
2023-07-22 16:05:44 +03:00
options.zfs-root.fileSystems = {
datasets = mkOption {
description = "Set mountpoint for datasets";
type = types.attrsOf types.str;
2024-07-29 15:39:54 +03:00
default = { };
2023-07-22 16:05:44 +03:00
};
bindmounts = mkOption {
description = "Set mountpoint for bindmounts";
type = types.attrsOf types.str;
2024-07-29 15:39:54 +03:00
default = { };
2023-07-22 16:05:44 +03:00
};
efiSystemPartitions = mkOption {
description = "Set mountpoint for efi system partitions";
type = types.listOf types.str;
2024-07-29 15:39:54 +03:00
default = [ ];
2023-07-22 16:05:44 +03:00
};
swapPartitions = mkOption {
description = "Set swap partitions";
type = types.listOf types.str;
2024-07-29 15:39:54 +03:00
default = [ ];
2023-07-22 16:05:44 +03:00
};
};
2024-07-29 15:39:54 +03:00
config.fileSystems = mkMerge (
mapAttrsToList (dataset: mountpoint: {
2023-07-22 16:05:44 +03:00
"${mountpoint}" = {
device = "${dataset}";
fsType = "zfs";
2024-07-29 15:39:54 +03:00
options = [
"X-mount.mkdir"
"noatime"
];
2023-07-22 16:05:44 +03:00
neededForBoot = true;
};
2024-07-29 15:39:54 +03:00
}) cfg.datasets
2023-07-22 16:05:44 +03:00
++ mapAttrsToList (bindsrc: mountpoint: {
"${mountpoint}" = {
device = "${bindsrc}";
fsType = "none";
2024-07-29 15:39:54 +03:00
options = [
"bind"
"X-mount.mkdir"
"noatime"
];
2023-07-22 16:05:44 +03:00
};
2024-07-29 15:39:54 +03:00
}) cfg.bindmounts
2023-07-22 16:05:44 +03:00
++ map (esp: {
"/boot/efis/${esp}" = {
device = "${config.zfs-root.boot.devNodes}${esp}";
fsType = "vfat";
options = [
"x-systemd.idle-timeout=1min"
"x-systemd.automount"
"noauto"
"nofail"
"noatime"
"X-mount.mkdir"
];
};
2024-07-29 15:39:54 +03:00
}) cfg.efiSystemPartitions
);
config.swapDevices = mkDefault (
map (swap: {
2023-07-22 16:05:44 +03:00
device = "${config.zfs-root.boot.devNodes}${swap}";
discardPolicy = mkDefault "both";
randomEncryption = {
enable = true;
allowDiscards = mkDefault true;
};
2024-07-29 15:39:54 +03:00
}) cfg.swapPartitions
);
2023-07-22 16:05:44 +03:00
}