summaryrefslogtreecommitdiff
path: root/modules/bootloader.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/bootloader.nix')
-rw-r--r--modules/bootloader.nix100
1 files changed, 100 insertions, 0 deletions
diff --git a/modules/bootloader.nix b/modules/bootloader.nix
new file mode 100644
index 0000000..e8dfc11
--- /dev/null
+++ b/modules/bootloader.nix
@@ -0,0 +1,100 @@
+{
+ 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";
+ };
+ };
+
+ #TODO add boot.initrd.luks.reusePassphrases = true; somewhere
+ 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;
+ };
+ })
+ ];
+}