2024-01-02 14:47:14 +08:00
|
|
|
{ pkgs
|
|
|
|
, lib
|
|
|
|
, config
|
|
|
|
, ... }: with lib; let
|
2024-01-07 22:01:31 +08:00
|
|
|
cfg = config.global.kernel;
|
2024-01-02 14:47:14 +08:00
|
|
|
in {
|
2024-01-07 22:01:31 +08:00
|
|
|
options.global.kernel = {
|
2024-01-02 14:47:14 +08:00
|
|
|
enable = mkEnableOption "kernel version and configuration" // { default = true; };
|
|
|
|
lts = mkEnableOption "longterm kernel releases";
|
|
|
|
sysctl = {
|
|
|
|
enable = mkEnableOption "sysctl presets" // { default = true; };
|
|
|
|
harden = mkEnableOption "hardening sysctls" // { default = true; };
|
|
|
|
swappiness = mkOption {
|
|
|
|
type = with types; int;
|
|
|
|
default = 0;
|
|
|
|
description = "vm.swappiness value, should be zero for low memory SSD systems";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
boot.kernel.sysctl = {
|
|
|
|
"kernel.dmesg_restrict" = mkIf cfg.sysctl.harden 1;
|
|
|
|
"vm.swappiness" = cfg.sysctl.swappiness;
|
|
|
|
};
|
2024-01-24 08:38:04 +08:00
|
|
|
boot.kernelPackages = with pkgs; mkOverride 1001 (if cfg.lts then linuxPackages else linuxPackages_latest);
|
2024-01-02 14:47:14 +08:00
|
|
|
};
|
|
|
|
}
|