{ config, lib, pkgs, ... }:
{
  options.system.video.nvidia.enable = lib.mkEnableOption "Enable the Nvidia graphics stack";

  config = lib.mkIf config.system.video.nvidia.enable {
    hardware = {
      nvidia = lib.mkIf config.system.video.nvidia.enable {
        modesetting.enable = true;
        nvidiaSettings = false;
        package = config.boot.kernelPackages.nvidiaPackages.beta;
        open = false;
      };
      graphics.extraPackages = with pkgs; [ nvidia-vaapi-driver ];
    };
    
    services.xserver.videoDrivers = [ "nvidia" ];
    boot.kernelParams = [ "nvidia_drm.fbdev=1" ];

    nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "nvidia-x11" ];
  };
}
