From 5bef7c46a6e2e182c3d41da4769653b559330a54 Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Sun, 27 Apr 2025 00:20:25 +0800 Subject: [PATCH] refactor(nixosmodules): move boot config to module --- configs/boot.nix | 30 ---------------- configs/bootloaders/systemd-boot.nix | 6 ---- hosts/apollo.nix | 2 +- hosts/common.nix | 2 +- hosts/mellinoe.nix | 16 --------- hosts/nemesis.nix | 2 +- nixosModules/boot.nix | 51 ++++++++++++++++++++++++++++ nixosModules/default.nix | 5 ++- nixosModules/nix-config.nix | 4 ++- 9 files changed, 61 insertions(+), 57 deletions(-) delete mode 100644 configs/boot.nix delete mode 100644 configs/bootloaders/systemd-boot.nix delete mode 100644 hosts/mellinoe.nix create mode 100644 nixosModules/boot.nix diff --git a/configs/boot.nix b/configs/boot.nix deleted file mode 100644 index b67328f..0000000 --- a/configs/boot.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ - pkgs, - modulesPath, - lib, - ... -}: -{ - imports = [ - (modulesPath + "/installer/scan/not-detected.nix") - ]; - boot = { - loader = { - timeout = 5; - efi.canTouchEfiVariables = true; - }; - kernelPackages = lib.mkDefault pkgs.linuxPackages_latest; - initrd.availableKernelModules = [ - "ahci" - "nvme" - "sd_mod" - "usb_storage" - "usbhid" - "xhci_pci" - "rtsx_pci_sdmmc" - ]; - }; - services.dbus = { - enable = true; - }; -} diff --git a/configs/bootloaders/systemd-boot.nix b/configs/bootloaders/systemd-boot.nix deleted file mode 100644 index 9d16cfc..0000000 --- a/configs/bootloaders/systemd-boot.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - boot.loader = { - systemd-boot.enable = true; - systemd-boot.configurationLimit = 5; - }; -} diff --git a/hosts/apollo.nix b/hosts/apollo.nix index 9b59f5f..34f2973 100644 --- a/hosts/apollo.nix +++ b/hosts/apollo.nix @@ -1,11 +1,11 @@ { lib, config, ... }: { imports = [ - ../configs/bootloaders/systemd-boot.nix ../configs/filesystems/impermanence.nix ../configs/services.nix ]; boot.kernelModules = [ "kvm-intel" ]; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + boot-config.bootloader = "systemd-boot"; } diff --git a/hosts/common.nix b/hosts/common.nix index b9cfd82..d6cf9f4 100644 --- a/hosts/common.nix +++ b/hosts/common.nix @@ -3,7 +3,6 @@ imports = [ ../nixosModules - ../configs/boot.nix ../configs/security.nix ../configs/users.nix ../configs/networking.nix @@ -15,4 +14,5 @@ ]; nixosModules.enable = true; nix-config.enable = true; + boot-config.enable = true; } diff --git a/hosts/mellinoe.nix b/hosts/mellinoe.nix deleted file mode 100644 index 016df46..0000000 --- a/hosts/mellinoe.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ - inputs, - lib, - config, - ... -}: -{ - imports = [ - ../configs/bootloaders/systemd-boot.nix - ../configs/filesystems/impermanence.nix - inputs.nixos-hardware.nixosModules.microsoft-surface-go - ]; - boot.kernelModules = [ "kvm-intel" ]; - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; - hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; -} diff --git a/hosts/nemesis.nix b/hosts/nemesis.nix index a0d7f33..23fb551 100644 --- a/hosts/nemesis.nix +++ b/hosts/nemesis.nix @@ -6,7 +6,6 @@ }: { imports = [ - ../configs/bootloaders/systemd-boot.nix ../configs/filesystems/hw-nemesis.nix ../configs/hardware/nvidia.nix ../configs/hardware/powermanagement.nix @@ -15,4 +14,5 @@ boot.kernelModules = [ "kvm-amd" ]; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + boot-config.bootloader = "systemd-boot"; } diff --git a/nixosModules/boot.nix b/nixosModules/boot.nix new file mode 100644 index 0000000..478add5 --- /dev/null +++ b/nixosModules/boot.nix @@ -0,0 +1,51 @@ +{ + config, + lib, + pkgs, + modulesPath, + ... +}: +let + moduleName = "boot-config"; + cfg = config."${moduleName}"; +in +{ + options = { + "${moduleName}" = { + enable = lib.mkEnableOption "Enable ${moduleName}."; + bootloader = lib.mkOption { + type = lib.types.str; + default = ""; + example = "systemd-boot"; + description = "What bootloader to use."; + }; + }; + }; + + config = lib.mkIf cfg.enable { + boot = { + loader = + { + timeout = 5; + efi.canTouchEfiVariables = true; + } + // lib.mkIf (cfg.bootloader == "systemd-boot") { + systemd-boot.enable = true; + systemd-boot.configurationLimit = 5; + }; + kernelPackages = lib.mkDefault pkgs.linuxPackages_latest; + initrd.availableKernelModules = [ + "ahci" + "nvme" + "sd_mod" + "usb_storage" + "usbhid" + "xhci_pci" + "rtsx_pci_sdmmc" + ]; + }; + services.dbus = { + enable = true; + }; + }; +} diff --git a/nixosModules/default.nix b/nixosModules/default.nix index f8c572c..00b8fa5 100644 --- a/nixosModules/default.nix +++ b/nixosModules/default.nix @@ -11,10 +11,13 @@ in { imports = [ ./nix-config.nix + ./boot.nix ]; options = { - "${moduleName}".enable = lib.mkEnableOption "Enable ${moduleName}."; + "${moduleName}" = { + enable = lib.mkEnableOption "Enable ${moduleName}."; + }; }; config = lib.mkIf cfg.enable { diff --git a/nixosModules/nix-config.nix b/nixosModules/nix-config.nix index 0839aef..2e3bd99 100644 --- a/nixosModules/nix-config.nix +++ b/nixosModules/nix-config.nix @@ -10,7 +10,9 @@ let in { options = { - "${moduleName}".enable = lib.mkEnableOption "Enable ${moduleName}."; + "${moduleName}" = { + enable = lib.mkEnableOption "Enable ${moduleName}."; + }; }; config = lib.mkIf cfg.enable {