[Boot+Treewide] rename aviallon.boot.kernel to aviallon.boot.kernel.package

Rename aviallon.boot.extraKCflags to aviallon.boot.kernel.addOptimizationAttributes

Also add an option to add non-optimization attributes to kernel derivation.
This commit is contained in:
Antoine Viallon 2023-11-07 21:27:57 +01:00
parent 418f672a18
commit ec9cfceda6
Signed by: aviallon
GPG key ID: 186FC35EDEB25716
3 changed files with 48 additions and 29 deletions

View file

@ -104,7 +104,7 @@ let
isXanmod = kernel: ! isNull (strings.match ".*(xanmod).*" kernel.modDirVersion); isXanmod = kernel: ! isNull (strings.match ".*(xanmod).*" kernel.modDirVersion);
kernelVersionOlder = ver: versionOlder cfg.kernel.version ver; kernelVersionOlder = ver: versionOlder cfg.kernel.package.version ver;
cfg = config.aviallon.boot; cfg = config.aviallon.boot;
generalCfg = config.aviallon.general; generalCfg = config.aviallon.general;
@ -173,23 +173,36 @@ in {
type = types.attrsOf (types.oneOf [ types.bool types.int types.str (types.listOf types.str) ]); type = types.attrsOf (types.oneOf [ types.bool types.int types.str (types.listOf types.str) ]);
}; };
kernel = mkOption { kernel = {
description = "Linux kernel to use"; package = mkOption {
default = options.boot.kernelPackages.default.kernel; description = "Linux kernel to use";
example = "pkgs.kernel"; default = options.boot.kernelPackages.default.kernel;
type = types.package; example = "pkgs.kernel";
}; type = types.package;
};
extraKCflags = mkOption { addAttributes = mkOption {
description = "If optimizations are enabled, add the specified values to kernel KCFLAGS"; description = "Merge specified attributes to kernel derivation (via special overideAttrs)";
default = []; default = {};
type = types.listOf types.string; type = with types; attrs;
example = [ "-fipa-pta" ]; example = { KCFLAGS = "-Wall"; };
};
addOptimizationAttributes = mkOption {
description = "Merge specified attributes to kernel derivation IF aviallon.optimizations.enabled is true";
default = {};
type = with types; attrs;
example = { KCFLAGS = "-O3 -fipa-pta"; };
};
}; };
removeKernelDRM = mkEnableOption "convert all EXPORT_SYMBOL_GPL to EXPORT_SYMBOL. Warning: might be illegal in your region."; removeKernelDRM = mkEnableOption "convert all EXPORT_SYMBOL_GPL to EXPORT_SYMBOL. Warning: might be illegal in your region.";
}; };
imports = [
( mkRemovedOptionModule [ "aviallon" "boot" "extraKCflags" ] "Replaced by aviallon.boot.kernel.addOptimizationAttributes attrset" )
];
config = mkMerge [ config = mkMerge [
{ {
assertions = [ assertions = [
@ -231,27 +244,33 @@ in {
initrd.kernelModules = [ ]; initrd.kernelModules = [ ];
initrd.availableKernelModules = [ "ehci_pci" ]; initrd.availableKernelModules = [ "ehci_pci" ];
kernelPackages = let kernelPackages = with myLib.debug; let
baseKernel = cfg.kernel; baseKernel = cfg.kernel.package;
# Possible CFLAGS source : (myLib.optimizations.makeOptimizationFlags {}).CFLAGS # Possible CFLAGS source : (myLib.optimizations.makeOptimizationFlags {}).CFLAGS
kCflags = kCflags = traceValWithPrefix "kCflags" (
[ [
"-march=${cpuConfig.arch}" "-march=${cpuConfig.arch}"
"-mtune=${cpuConfig.tune or cpuConfig.arch}" "-mtune=${cpuConfig.tune or cpuConfig.arch}"
] ]
++ optional (! isNull cpuConfig.caches.lastLevel ) "--param l2-cache-size=${toString cpuConfig.caches.lastLevel}" ++ optional (! isNull cpuConfig.caches.lastLevel ) "--param l2-cache-size=${toString cpuConfig.caches.lastLevel}"
++ optional (! isNull cpuConfig.caches.l1d ) "--param l1-cache-size=${toString cpuConfig.caches.l1d}" ++ optional (! isNull cpuConfig.caches.l1d ) "--param l1-cache-size=${toString cpuConfig.caches.l1d}"
++ cfg.extraKCflags; );
optimizedKernel =
if config.aviallon.optimizations.enable then optimizedKernelAttrs = traceValWithPrefix "optimizedKernelAttrs" (
baseKernel.overrideAttrs (old: { optionalAttrs config.aviallon.optimizations.enable (
KCFLAGS = (old.KCFLAGS or "") + (toString kCflags); myLib.attrsets.mergeAttrsRecursive
passthru = baseKernel.passthru; {
}) KCFLAGS = kCflags;
else }
baseKernel (traceValWithPrefix "aviallon.boot.kernel.addOptimizationAttributes" cfg.kernel.addOptimizationAttributes)
; )
in mkOverride 2 (pkgs.linuxPackagesFor optimizedKernel); );
moddedKernelAttrs = traceValWithPrefix "moddedKernelAttrs" (
myLib.attrsets.mergeAttrsRecursive (traceValWithPrefix "aviallon.boot.kernel.addAttributes" cfg.kernel.addAttributes) optimizedKernelAttrs
);
moddedKernel = myLib.optimizations.addAttrs baseKernel moddedKernelAttrs;
in mkOverride 2 (pkgs.linuxPackagesFor moddedKernel);
kernelPatches = [] kernelPatches = []
++ optional cfg.x32abi.enable customKernelPatches.enableX32ABI ++ optional cfg.x32abi.enable customKernelPatches.enableX32ABI
@ -259,7 +278,7 @@ in {
++ optional cfg.energyModel.enable customKernelPatches.enableEnergyModel ++ optional cfg.energyModel.enable customKernelPatches.enableEnergyModel
++ optional (cfg.patches.amdClusterId.enable && kernelVersionOlder "6.4") customKernelPatches.amdClusterId ++ optional (cfg.patches.amdClusterId.enable && kernelVersionOlder "6.4") customKernelPatches.amdClusterId
++ optional (cfg.patches.zenLLCIdle.enable && kernelVersionOlder "6.5") customKernelPatches.backports.zenLLCIdle ++ optional (cfg.patches.zenLLCIdle.enable && kernelVersionOlder "6.5") customKernelPatches.backports.zenLLCIdle
++ optional (isXanmod cfg.kernel && config.aviallon.optimizations.enable) (customKernelPatches.optimizeForCPUArch config.aviallon.general.cpu.arch) ++ optional (isXanmod cfg.kernel.package && config.aviallon.optimizations.enable) (customKernelPatches.optimizeForCPUArch config.aviallon.general.cpu.arch)
++ optional cfg.removeKernelDRM customKernelPatches.removeKernelDRM ++ optional cfg.removeKernelDRM customKernelPatches.removeKernelDRM
; ;

View file

@ -57,7 +57,7 @@ in {
{ {
aviallon.network.backend = mkDefault "NetworkManager"; aviallon.network.backend = mkDefault "NetworkManager";
aviallon.boot.kernel = pkgs.linuxKernel.kernels.linux_xanmod; aviallon.boot.kernel.package = pkgs.linuxKernel.kernels.linux_xanmod;
# Enable the X11 windowing system. # Enable the X11 windowing system.
services.xserver.enable = true; services.xserver.enable = true;

View file

@ -41,7 +41,7 @@ in
# imports = [ # imports = [
# (modulesPath + "/profiles/hardened.nix") # (modulesPath + "/profiles/hardened.nix")
# ]; # ];
aviallon.boot.kernel = mkIf cfg.hardcore pkgs.linuxKernel.kernels.linux_hardened; aviallon.boot.kernel.package = mkIf cfg.hardcore pkgs.linuxKernel.kernels.linux_hardened;
security.lockKernelModules = mkIf cfg.hardcore (mkOverride 500 true); security.lockKernelModules = mkIf cfg.hardcore (mkOverride 500 true);
# security.protectKernelImage = mkIf cfg.hardcore (mkOverride 500 false); # needed for kexec # security.protectKernelImage = mkIf cfg.hardcore (mkOverride 500 false); # needed for kexec