{ lib, config, ... }:
let
  inherit (lib) mkDefault mkForce mkOverride mkMerge mkIf optionals;
  sys = config.modules.system;
in {
  boot = {
    consoleLogLevel = 3;

    # always use the latest kernel, love the unstablity
    kernelPackages = mkOverride 500 sys.boot.kernel;

    # shared config between bootloaders
    # they are set unless system.boot.loader != none
    loader = {
      # we need to allow installation to modify EFI variables
      efi.canTouchEfiVariables = true;
    };

    # initrd and kernel tweaks
    # read what each parameter or module does before doing so, it will defo break something otherwise
    initrd = mkMerge [
      (mkIf sys.boot.initrd.enableTweaks {
        # Verbosity of the initrd
        # disabling verbosity removes only the mandatory messages generated by the NixOS
        verbose = false;

        # List of modules that are loaded by the initrd
        kernelModules = [ "nvme" "xhci_pci" "ahci" "sd_mod" "dm_mod" ];

        # the set of kernel modules in the initial ramdisk used during the boot process
        availableKernelModules =
          [ "ehci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" ];
      })
    ];

    # https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html
    kernelParams = (optionals sys.boot.silentBoot [
      # tell the kernel to not be verbose, the voices are too loud
      "quiet"

      # kernel log message level
      "loglevel=3" # 1: system is unusable | 3: error condition | 7: very verbose

      # udev log message level
      "udev.log_level=3"

      # lower the udev log level to show only errors or worse
      "rd.udev.log_level=3"

      # disable systemd status messages
      # rd prefix means systemd-udev will be used instead of initrd
      "systemd.show_status=auto"
      "rd.systemd.show_status=auto"
    ]);
  };
}
