{
  config,
  pkgs,
  lib,
  systemConfig,
  ...
}:

lib.mkIf systemConfig.nvidia.enable {
  boot.kernelParams = [ "nvidia.NVreg_PreserveVideoMemoryAllocations=1" ];

  # For hardware acceleration
  environment.sessionVariables.LIBVA_DRIVER_NAME = "nvidia";

  hardware = {
    graphics.extraPackages = with pkgs; [
      # Used for hardware-acceleration
      nvidia-vaapi-driver
    ];
    nvidia = {
      # Required
      modesetting.enable = true;
      # Use open-source kernel module
      open = true;
      # Enable the Nvidia settings menu
      nvidiaSettings = true;
      # Enable nvidia-suspend.service, nvidia-hibernate.service and nvidia-resume.service
      powerManagement = {
        enable = true;
        finegrained = false;
      };

      package = config.boot.kernelPackages.nvidiaPackages.latest;
    };
  };

  # Load Nvidia driver for Xorg and Wayland
  services.xserver.videoDrivers = [ "nvidia" ];
}
