[Boot+Refactoring] Add a cmdline config option for cleaner boot option config

This commit is contained in:
Antoine Viallon 2022-04-07 09:22:44 +02:00
parent 8457628ee6
commit 7e26d25066
Signed by: aviallon
GPG key ID: 186FC35EDEB25716
6 changed files with 43 additions and 22 deletions

View file

@ -22,6 +22,13 @@ let
''; '';
}; };
}; };
toCmdlineValue = v: if (isBool v) then (if v then "y" else "n")
else if (isInt v || isString v) then (toString v)
else throw "Invalid value for kernel cmdline parameter";
toCmdlineList = set: mapAttrsToList (key: value: "${key}=${toCmdlineValue value}") set;
cfg = config.aviallon.boot; cfg = config.aviallon.boot;
generalCfg = config.aviallon.general; generalCfg = config.aviallon.general;
allowUnfree = (types.isType types.attrs config.nixpkgs.config) allowUnfree = (types.isType types.attrs config.nixpkgs.config)
@ -58,6 +65,13 @@ in
example = null; example = null;
type = types.int; type = types.int;
}; };
cmdline = mkOption {
description = "Kernel params as attributes (instead of list)";
default = { };
example = { "i915.fastboot" = true; };
type = types.attrsOf (types.oneOf [ types.bool types.int types.str ]);
};
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
@ -65,14 +79,16 @@ in
hardware.enableAllFirmware = allowUnfree; hardware.enableAllFirmware = allowUnfree;
hardware.enableRedistributableFirmware = true; hardware.enableRedistributableFirmware = true;
aviallon.boot.cmdline = {
"syscall.x32" = cfg.x32abi.enable;
};
boot = { boot = {
initrd.kernelModules = [ ]; initrd.kernelModules = [ ];
initrd.availableKernelModules = [ "ehci_pci" ]; initrd.availableKernelModules = [ "ehci_pci" ];
kernelParams = concatLists [ kernelParams = toCmdlineList cfg.cmdline;
(optional cfg.x32abi.enable "syscall.x32=y")
];
kernelPatches = concatLists [ kernelPatches = concatLists [
(optional cfg.x32abi.enable customKernelPatches.enableX32ABI) (optional cfg.x32abi.enable customKernelPatches.enableX32ABI)
]; ];

View file

@ -70,10 +70,11 @@ in {
boot.plymouth.enable = mkDefault true; boot.plymouth.enable = mkDefault true;
boot.kernelParams = concatLists [ aviallon.boot.cmdline = {
(optionals (!generalCfg.debug) [ "splash" "udev.log_level=3" ]) splash = mkIf (!generalCfg.debug) true;
["preempt=full"] "udev.log_level" = mkIf (!generalCfg.debug) 3;
]; preempt = "full";
};
boot.initrd.verbose = generalCfg.debug; boot.initrd.verbose = generalCfg.debug;
boot.consoleLogLevel = mkIf (!generalCfg.debug) 1; boot.consoleLogLevel = mkIf (!generalCfg.debug) 1;

View file

@ -94,10 +94,12 @@ in
font = "Lat2-Terminus16"; font = "Lat2-Terminus16";
}; };
boot.kernelParams = concatLists [ aviallon.boot.cmdline = mkIf cfg.unsafeOptimizations {
(optional cfg.unsafeOptimizations "mitigations=off") mitigations = "off";
(optionals cfg.unsafeOptimizations [ "i915.mitigations=off" "i915.enable_dc=4" "i915.fastboot=1" ] ) "i915.mitigations" = "off";
]; "i915.enable_dc" = 4;
"i915.fastboot" = 1;
};
powerManagement.cpuFreqGovernor = mkDefault "schedutil"; powerManagement.cpuFreqGovernor = mkDefault "schedutil";

View file

@ -53,7 +53,7 @@ in
services.dbus.apparmor = "enabled"; services.dbus.apparmor = "enabled";
boot.kernelParams = concatLists [ boot.kernelParams = mkAfter (concatLists [
# Slab/slub sanity checks, redzoning, and poisoning # Slab/slub sanity checks, redzoning, and poisoning
(optional cfg.expensive "slub_debug=FZP") (optional cfg.expensive "slub_debug=FZP")
@ -65,7 +65,7 @@ in
# Apparmor https://wiki.archlinux.org/title/AppArmor#Installation # Apparmor https://wiki.archlinux.org/title/AppArmor#Installation
(optional cfg.expensive "lsm=landlock,lockdown,yama,apparmor,bpf") (optional cfg.expensive "lsm=landlock,lockdown,yama,apparmor,bpf")
]; ]);
boot.kernel.sysctl = { boot.kernel.sysctl = {
"kernel.yama.ptrace_scope" = mkOverride 500 1; "kernel.yama.ptrace_scope" = mkOverride 500 1;

View file

@ -7,12 +7,14 @@ in
config = mkIf (hardwareCfg.gpuVendor == "amd") { config = mkIf (hardwareCfg.gpuVendor == "amd") {
boot.initrd.kernelModules = [ "amdgpu" ]; boot.initrd.kernelModules = [ "amdgpu" ];
boot.kernelParams = concatLists [ aviallon.boot.cmdline = {}
# for Southern Islands (SI ie. GCN 1) cards # for Southern Islands (SI ie. GCN 1) cards
[ "radeon.si_support=0" "amdgpu.si_support=1" ] // { "radeon.si_support" = 0;
"amdgpu.si_support" = 1; }
# for Sea Islands (CIK ie. GCN 2) cards # for Sea Islands (CIK ie. GCN 2) cards
[ "radeon.cik_support=0" "amdgpu.cik_support=1" ] // { "radeon.cik_support" = 0;
]; "amdgpu.cik_support" = 1; }
;
hardware.opengl.extraPackages = with pkgs; [ hardware.opengl.extraPackages = with pkgs; [
rocm-opencl-icd rocm-opencl-icd

View file

@ -24,10 +24,10 @@ in {
hardware.sensor.iio.enable = mkDefault true; hardware.sensor.iio.enable = mkDefault true;
boot.kernelParams = [ aviallon.boot.cmdline = {
"i915.enable_fbc=1" "i915.enable_fbc" = 1;
"i915.enable_gvt=1" "i915.enable_gvt" = 1;
]; };
services.tlp.enable = (cfg.power-manager == "tlp"); services.tlp.enable = (cfg.power-manager == "tlp");
services.power-profiles-daemon.enable = (cfg.power-manager == "power-profiles-daemon"); services.power-profiles-daemon.enable = (cfg.power-manager == "power-profiles-daemon");