{ config, lib, ... }: let cfg = config.os.core.bootloader; in { options.os.core.bootloader = { type = lib.mkOption { type = lib.types.enum [ "systemd-boot" "grub" "none" ]; default = "systemd-boot"; description = "Which bootloader to use"; }; efi = lib.mkOption { type = lib.types.bool; default = if cfg.grub.device == "nodev" then true else false; description = "Whether the system uses UEFI or Legacy BIOS"; }; timeout = lib.mkOption { type = lib.types.int; default = 3; description = "Boot menu timeout in seconds"; }; grub = { device = lib.mkOption { type = lib.types.str; default = "nodev"; description = "Device to install GRUB to (e.g. /dev/nvme0n1). Use 'nodev' for UEFI."; }; useOSProber = lib.mkOption { type = lib.types.bool; default = false; description = "Scan for other operating systems"; }; defaultEntry = lib.mkOption { type = lib.types.int; default = 0; description = "Index of the default boot entry"; }; }; luks.enable = lib.mkEnableOption "LUKS encryption support"; }; config = lib.mkMerge [ # 1. Common Kernel & Initrd Settings { boot = { loader = { timeout = cfg.timeout; efi.canTouchEfiVariables = lib.mkDefault cfg.efi; }; supportedFilesystems = [ "ntfs" "btrfs" ]; kernelParams = [ "quiet" "splash" ]; consoleLogLevel = 0; initrd.availableKernelModules = [ "aesni_intel" "cryptd" ]; }; systemd.settings.Manager.DefaultTimeoutStopSec = "5s"; } # 2. Systemd-boot Implementation (lib.mkIf (cfg.type == "systemd-boot") { boot.loader.systemd-boot = { enable = true; editor = false; consoleMode = "max"; }; }) # 3. GRUB Implementation (lib.mkIf (cfg.type == "grub") { boot.loader.grub = { enable = true; efiSupport = cfg.efi; useOSProber = cfg.grub.useOSProber; default = cfg.grub.defaultEntry; enableCryptodisk = cfg.luks.enable; copyKernels = true; }; }) ]; }