mirror of
https://github.com/aviallon/nixos-lib.git
synced 2026-04-05 17:27:50 +00:00
115 lines
3.8 KiB
Nix
115 lines
3.8 KiB
Nix
{ config, pkgs, lib, ... }:
|
|
with lib;
|
|
let
|
|
cfg = config.aviallon.filesystems;
|
|
|
|
getSwapDevice = index: ifEnable (length config.swapDevices > index) (elemAt config.swapDevices index);
|
|
firstSwapDevice = getSwapDevice 0;
|
|
resumeDeviceLabel = attrByPath [ "label" ] null firstSwapDevice;
|
|
|
|
ioSchedType = types.enum [ "bfq" "kyber" "mq-deadline" "none" null ];
|
|
in
|
|
{
|
|
imports = [
|
|
./filesystems
|
|
];
|
|
|
|
options.aviallon.filesystems = {
|
|
enable = mkOption {
|
|
default = true;
|
|
example = false;
|
|
description = "Enable aviallon's filesystem tuning";
|
|
type = types.bool;
|
|
};
|
|
hddScheduler = mkOption {
|
|
default = "bfq";
|
|
example = null;
|
|
description = "Automatically set HDDs IO queue algorithm";
|
|
type = ioSchedType;
|
|
};
|
|
slowFlashScheduler = mkOption {
|
|
default = "kyber";
|
|
example = "none";
|
|
description = "Automatically set flash storage IO queue algorithm";
|
|
type = ioSchedType;
|
|
};
|
|
nvmeScheduler = mkOption {
|
|
default = "none";
|
|
example = "kyber";
|
|
description = "Automatically set NVMe IO queue algorithm";
|
|
type = ioSchedType;
|
|
};
|
|
queuePriority = mkOption {
|
|
default = true;
|
|
example = false;
|
|
description = "Automatically enable ncq_prio if it is supported by the SATA device.\nIt may improve latency.";
|
|
type = types.bool;
|
|
};
|
|
udevRules = mkOption {
|
|
default = [];
|
|
example = [ ''ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sda", ATTR{queue/scheduler}="none"'' ];
|
|
description = "Additional udev rules";
|
|
type = types.listOf types.str;
|
|
};
|
|
lvm = mkEnableOption "lvm options required for correct booting";
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.lvm = mkIf cfg.lvm {
|
|
boot.thin.enable = true;
|
|
dmeventd.enable = true;
|
|
};
|
|
boot.initrd.kernelModules = ifEnable cfg.lvm [
|
|
"dm-cache" "dm-cache-smq" "dm-cache-mq" "dm-cache-cleaner"
|
|
];
|
|
boot.kernelModules = ifEnable cfg.lvm [ "dm-cache" "dm-cache-smq" "dm-persistent-data" "dm-bio-prison" "dm-clone" "dm-crypt" "dm-writecache" "dm-mirror" "dm-snapshot" "kvdo" ];
|
|
aviallon.boot.kvdo.enable = mkDefault cfg.lvm;
|
|
|
|
aviallon.boot.cmdline = {
|
|
resume = mkIf (! isNull resumeDeviceLabel) (mkDefault "LABEL=${resumeDeviceLabel}");
|
|
};
|
|
|
|
fileSystems."/boot".neededForBoot = mkDefault true;
|
|
|
|
boot.supportedFilesystems = [ "ntfs" "ext4" "vfat" "exfat" ];
|
|
|
|
aviallon.filesystems.udevRules = mkBefore (concatLists [
|
|
(optional (!(builtins.isNull cfg.hddScheduler))
|
|
''ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sd[a-z]*", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="${cfg.hddScheduler}"''
|
|
)
|
|
(optional (!(builtins.isNull cfg.slowFlashScheduler))
|
|
''ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sd[a-z]*|nvme[0-9]*n[0-9]*|mmcblk[0-9]*", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="${cfg.slowFlashScheduler}"''
|
|
)
|
|
(optional (!(builtins.isNull cfg.nvmeScheduler))
|
|
''ACTION!="remove", SUBSYSTEM=="block", KERNEL=="nvme[0-9]*n[0-9]*", ATTR{queue/scheduler}="${cfg.nvmeScheduler}"''
|
|
)
|
|
(optional cfg.queuePriority
|
|
''ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sd[a-z]*", ATTR{device/ncq_prio_supported}=="1", ATTR{device/ncq_prio_enable}="1"''
|
|
)
|
|
]);
|
|
|
|
boot.initrd.services.udev.rules = concatStringsSep "\n" cfg.udevRules;
|
|
|
|
services.udev = {
|
|
extraRules = concatStringsSep "\n" cfg.udevRules;
|
|
};
|
|
|
|
boot.tmpOnTmpfs = true;
|
|
|
|
services.smartd = {
|
|
enable = mkDefault true;
|
|
autodetect = true;
|
|
defaults.autodetected = "-a -o on -s (S/../.././02|L/../../7/04)";
|
|
notifications.mail = {
|
|
enable = true;
|
|
sender = "admin@${config.networking.hostName}.local";
|
|
recipient = "antoine@lesviallon.fr";
|
|
};
|
|
notifications.x11 = {
|
|
enable = true;
|
|
display = ":0";
|
|
};
|
|
};
|
|
};
|
|
}
|