modularizing kernel and loader settings

This commit is contained in:
cnst
2024-09-22 14:30:06 +02:00
parent 6f53da8393
commit 50d554b6f6
22 changed files with 294 additions and 84 deletions

View File

@@ -0,0 +1,72 @@
# kernel.nix
{
pkgs,
lib,
config,
...
}: let
inherit (lib) mkOption;
cfg = config.modules.boot.kernel;
in {
options = {
modules.boot.kernel = {
variant = mkOption {
type = lib.types.enum ["latest" "cachyos"];
default = "latest";
description = "Kernel variant to use.";
};
hardware = mkOption {
type = lib.types.enum ["amd" "nvidia"];
default = "amd";
description = "Hardware type (GPU) configuration.";
};
extraKernelParams = mkOption {
type = lib.types.listOf lib.types.str;
default = [];
description = "Additional kernel parameters.";
};
extraBlacklistedModules = mkOption {
type = lib.types.listOf lib.types.str;
default = [];
description = "Additional kernel modules to blacklist.";
};
};
};
config = {
boot = {
consoleLogLevel = 3;
kernelPackages = (
if cfg.variant == "latest"
then pkgs.linuxPackages_latest
else if cfg.variant == "cachyos"
then pkgs.linuxPackages_cachyos
else pkgs.linuxPackages
);
kernelParams =
[
"quiet"
"splash"
]
++ (
if cfg.hardware == "amd"
then ["amd_pstate=active"]
else []
)
++ cfg.extraKernelParams;
blacklistedKernelModules =
(
if cfg.hardware == "nvidia"
then ["nouveau"]
else []
)
++ cfg.extraBlacklistedModules;
};
};
}

View File

@@ -0,0 +1,60 @@
{
pkgs,
lib,
config,
inputs,
...
}: let
inherit (lib) mkIf mkEnableOption mkMerge mkForce;
cfg = config.modules.boot.loader;
in {
options = {
modules.boot.loader = {
default = {
enable = mkEnableOption "Enable default boot loader configuration.";
};
lanzaboote = {
enable = mkEnableOption "Enable Lanzaboote boot loader configuration.";
};
};
};
imports = [
inputs.lanzaboote.nixosModules.lanzaboote
];
config = mkMerge [
{
assertions = [
{
assertion = !(cfg.default.enable && cfg.lanzaboote.enable);
message = "Only one of modules.boot.loader.default.enable and modules.boot.loader.lanzaboote.enable can be set to true.";
}
];
}
(mkIf cfg.default.enable {
# Default boot loader configuration
boot.loader = {
systemd-boot.enable = true;
systemd-boot.graceful = true;
efi.canTouchEfiVariables = false;
};
})
(mkIf cfg.lanzaboote.enable {
# Lanzaboote boot loader configuration
boot = {
lanzaboote = {
enable = true;
pkiBundle = "/etc/secureboot";
};
# We let Lanzaboote install systemd-boot
loader.systemd-boot.enable = mkForce false;
};
environment.systemPackages = [pkgs.sbctl];
})
];
}

View File

@@ -1,5 +1,7 @@
{systemModules, ...}: {
imports = [
"${systemModules}/boot/loader"
"${systemModules}/boot/kernel"
"${systemModules}/gaming/gamemode"
"${systemModules}/gaming/gamescope"
"${systemModules}/gaming/lutris"
@@ -40,6 +42,7 @@
"${systemModules}/utils/android"
"${systemModules}/utils/anyrun"
"${systemModules}/utils/brightnessctl"
"${systemModules}/utils/chaotic"
"${systemModules}/utils/corectrl"
"${systemModules}/utils/microfetch"
"${systemModules}/utils/misc"

View File

@@ -20,15 +20,7 @@ in {
vaapiVdpau
libvdpau-va-gl
amdvlk
# mesa
mesa
# vulkan
vulkan-tools
# vulkan-loader
# vulkan-validation-layers
# vulkan-extension-layer
];
extraPackages32 = with pkgs.pkgsi686Linux; [
vaapiVdpau

View File

@@ -18,9 +18,9 @@ in {
modules.hardware.graphics.nvidia = {
enable = mkEnableOption "Enables NVidia graphics";
package = mkOption {
type = types.enum ["stable" "beta" "production"]; # Added "production" here
type = types.enum ["stable" "beta" "production" "latest"];
default = "stable";
description = "Choose between the stable, beta, or production NVidia driver package";
description = "Choose between the stable, beta, latest, or production NVidia driver package";
};
};
};
@@ -49,15 +49,17 @@ in {
package =
if cfg.package == "beta"
then config.boot.kernelPackages.nvidiaPackages.beta
else if cfg.package == "latest"
then config.boot.kernelPackages.nvidiaPackages.latest
else if cfg.package == "production"
then config.boot.kernelPackages.nvidiaPackages.production
then config.boot.kernelPackages.nvidiaPackages.prodution
else config.boot.kernelPackages.nvidiaPackages.stable;
modesetting.enable = true;
powerManagement = {
enable = false;
finegrained = false;
};
open = false;
open = true;
nvidiaSettings = true;
};
};

View File

@@ -0,0 +1,44 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption mkOption mkMerge;
cfg = config.modules.utils.chaotic;
in {
options = {
modules.utils.chaotic = {
enable = mkEnableOption "Enables Chaotic AUR packages";
amd.enable = mkOption {
type = lib.types.bool;
default = false;
description = "Whether to install AMD-specific settings.";
};
};
};
config = mkIf cfg.enable (mkMerge [
{
# Base configuration when Chaotic is enabled
chaotic.scx.enable = true;
}
(mkIf cfg.amd.enable {
# AMD-specific configuration
chaotic.mesa-git = {
enable = true;
extraPackages = with pkgs; [
mesa_git.opencl
intel-media-driver
intel-ocl
vaapiIntel
];
extraPackages32 = with pkgs; [
mesa32_git.opencl
intel-media-driver
vaapiIntel
];
};
})
]);
}