From bca6c112700dcb447cc8102ca634f6ca60557453 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Sun, 21 Nov 2021 19:58:03 -0500 Subject: [PATCH] modules/boot: move bootloaders to module --- hosts/Infini-DESKTOP/default.nix | 4 +-- hosts/Infini-FRAMEWORK/default.nix | 4 +-- hosts/Infini-SERVER/default.nix | 7 ++-- hosts/Infini-STICK/default.nix | 9 +++-- modules/modules/boot.nix | 56 ++++++++++++++++++++++++++++++ profiles/boot/grub.nix | 17 --------- profiles/boot/systemd-boot.nix | 14 -------- 7 files changed, 66 insertions(+), 45 deletions(-) create mode 100644 modules/modules/boot.nix delete mode 100644 profiles/boot/grub.nix delete mode 100644 profiles/boot/systemd-boot.nix diff --git a/hosts/Infini-DESKTOP/default.nix b/hosts/Infini-DESKTOP/default.nix index 2771664..2f968f8 100644 --- a/hosts/Infini-DESKTOP/default.nix +++ b/hosts/Infini-DESKTOP/default.nix @@ -6,13 +6,10 @@ ]) (with profiles; [ - boot.grub - networking.wireless (with hardware; [ gpu.nvidia - wireless ]) btrfs @@ -29,6 +26,7 @@ system.stateVersion = "21.05"; modules = { + boot.grub.enable = true; hardware = { wireless.enable = true; form.desktop = true; diff --git a/hosts/Infini-FRAMEWORK/default.nix b/hosts/Infini-FRAMEWORK/default.nix index 202218d..92ec885 100644 --- a/hosts/Infini-FRAMEWORK/default.nix +++ b/hosts/Infini-FRAMEWORK/default.nix @@ -3,13 +3,10 @@ (with suites; [ graphic ]) (with profiles; [ - boot.grub - networking.wireless (with hardware; [ gpu.intel - wireless ]) # services.privoxy @@ -45,6 +42,7 @@ }; modules = { + boot.grub.enable = true; hardware = { form.laptop = true; }; diff --git a/hosts/Infini-SERVER/default.nix b/hosts/Infini-SERVER/default.nix index 751d52d..94b7eee 100644 --- a/hosts/Infini-SERVER/default.nix +++ b/hosts/Infini-SERVER/default.nix @@ -3,11 +3,12 @@ suites = with suites; [ base ]; imports = [ ]; profiles = with profiles; [ - boot.grub - hardware.gpu.nvidia ]; }; - modules.hardware.form.server = true; + modules = { + boot.grub.enable = true; + hardware.form.server = true; + }; } diff --git a/hosts/Infini-STICK/default.nix b/hosts/Infini-STICK/default.nix index 45060d1..ae462ea 100644 --- a/hosts/Infini-STICK/default.nix +++ b/hosts/Infini-STICK/default.nix @@ -3,8 +3,6 @@ (with suites; [ base develop ]) (with profiles; [ - boot.grub - networking.wireless (with hardware; [ @@ -14,8 +12,6 @@ intel nvidia ]) - laptop - wireless ]) btrfs @@ -29,7 +25,10 @@ # networking.interfaces.wlp170s0.useDHCP = true; networking.interfaces.enp39s0.useDHCP = true; - modules.hardware.form.portable = true; + modules = { + boot.grub.enable = true; + hardware.form.portable = true; + }; system.stateVersion = "21.11"; } diff --git a/modules/modules/boot.nix b/modules/modules/boot.nix new file mode 100644 index 0000000..4541cd4 --- /dev/null +++ b/modules/modules/boot.nix @@ -0,0 +1,56 @@ +{ config, options, lib, ... }: +with lib; +with lib.hlissner; +let + cfg = config.modules.boot; + opt = options.modules.boot; +in +{ + options.modules.boot = with types; { + timeout = mkOpt (nullOr int) 3; + + grub = { + enable = mkBoolOpt false; + }; + systemd-boot.enable = mkBoolOpt false; + }; + + config = mkMerge [ + { + assertions = [ + { + assertion = (count (v: v) [ cfg.grub.enable cfg.systemd-boot.enable ]) == 1; + message = "Must enable one and only one bootloader"; + } + ]; + + boot.loader.timeout = mkAliasDefinitions opt.timeout; + } + (mkIf cfg.grub.enable { + boot.loader = { + grub = { + enable = mkDefault true; + device = mkDefault "nodev"; + efiSupport = mkDefault true; + useOSProber = mkDefault false; + efiInstallAsRemovable = mkDefault true; + }; + efi = { + canTouchEfiVariables = mkDefault false; + efiSysMountPoint = mkDefault "/boot/efi"; + }; + }; + }) + (mkIf cfg.systemd-boot.enable { + boot.loader = { + systemd-boot = { + enable = mkDefault true; + editor = false; + consoleMode = "2"; + }; + + efi.canTouchEfiVariables = true; + }; + }) + ]; +} diff --git a/profiles/boot/grub.nix b/profiles/boot/grub.nix deleted file mode 100644 index d68cb27..0000000 --- a/profiles/boot/grub.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ lib, ... }: -with lib; -{ - boot.loader = { - grub = { - enable = mkDefault true; - device = mkDefault "nodev"; - efiSupport = mkDefault true; - useOSProber = mkDefault false; - efiInstallAsRemovable = mkDefault true; - }; - efi = { - canTouchEfiVariables = mkDefault false; - efiSysMountPoint = mkDefault "/boot/efi"; - }; - }; -} diff --git a/profiles/boot/systemd-boot.nix b/profiles/boot/systemd-boot.nix deleted file mode 100644 index 4a8d189..0000000 --- a/profiles/boot/systemd-boot.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ lib, ... }: -with lib; -{ - boot.loader = { - systemd-boot = { - enable = mkDefault true; - editor = false; - consoleMode = "2"; - }; - - efi.canTouchEfiVariables = true; - timeout = mkDefault 3; - }; -}