mirror of
https://github.com/aviallon/nixos-lib.git
synced 2026-04-06 01:38:06 +00:00
[Boot/Optimizations] use CPU informations to optimize kernel + add option to specify extra CFLAGS for kernel build
This commit is contained in:
parent
bd1e3fe6bf
commit
8c76734e33
1 changed files with 31 additions and 2 deletions
33
boot.nix
33
boot.nix
|
|
@ -1,4 +1,4 @@
|
||||||
{ config, pkgs, lib, options, ... }:
|
{ config, pkgs, lib, myLib, options, ... }:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
customKernelPatches = {
|
customKernelPatches = {
|
||||||
|
|
@ -105,6 +105,8 @@ let
|
||||||
allowUnfree = (types.isType types.attrs config.nixpkgs.config)
|
allowUnfree = (types.isType types.attrs config.nixpkgs.config)
|
||||||
&& (hasAttr "allowUnfree" config.nixpkgs.config)
|
&& (hasAttr "allowUnfree" config.nixpkgs.config)
|
||||||
&& (getAttr "allowUnfree" config.nixpkgs.config);
|
&& (getAttr "allowUnfree" config.nixpkgs.config);
|
||||||
|
|
||||||
|
cpuConfig = config.aviallon.general.cpu;
|
||||||
in {
|
in {
|
||||||
|
|
||||||
options.aviallon.boot = {
|
options.aviallon.boot = {
|
||||||
|
|
@ -171,6 +173,13 @@ in {
|
||||||
example = "pkgs.kernel";
|
example = "pkgs.kernel";
|
||||||
type = types.package;
|
type = types.package;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extraKCflags = mkOption {
|
||||||
|
description = "If optimizations are enabled, add the specified values to kernel KCFLAGS";
|
||||||
|
default = [];
|
||||||
|
type = types.listOf types.string;
|
||||||
|
example = [ "-fipa-pta" ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkMerge [
|
config = mkMerge [
|
||||||
|
|
@ -214,7 +223,27 @@ in {
|
||||||
initrd.kernelModules = [ ];
|
initrd.kernelModules = [ ];
|
||||||
initrd.availableKernelModules = [ "ehci_pci" ];
|
initrd.availableKernelModules = [ "ehci_pci" ];
|
||||||
|
|
||||||
kernelPackages = mkOverride 2 (pkgs.linuxPackagesFor cfg.kernel);
|
kernelPackages = let
|
||||||
|
baseKernel = cfg.kernel;
|
||||||
|
# Possible CFLAGS source : (myLib.optimizations.makeOptimizationFlags {}).CFLAGS
|
||||||
|
kCflags =
|
||||||
|
[
|
||||||
|
"-march=${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.l1d ) "--param l1-cache-size=${toString cpuConfig.caches.l1d}"
|
||||||
|
++ cfg.extraKCflags;
|
||||||
|
optimizedKernel =
|
||||||
|
if config.aviallon.optimizations.enable then
|
||||||
|
baseKernel.overrideAttrs (old: {
|
||||||
|
KCFLAGS = (old.KCFLAGS or "") + (toString kCflags);
|
||||||
|
passthru = baseKernel.passthru;
|
||||||
|
})
|
||||||
|
else
|
||||||
|
baseKernel
|
||||||
|
;
|
||||||
|
in mkOverride 2 (pkgs.linuxPackagesFor optimizedKernel);
|
||||||
|
|
||||||
kernelPatches = []
|
kernelPatches = []
|
||||||
++ optional cfg.x32abi.enable customKernelPatches.enableX32ABI
|
++ optional cfg.x32abi.enable customKernelPatches.enableX32ABI
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue