{ config, lib, ... }:

with lib;

let
  cfg = config.settings.hardware.nvidia;
in {
  options = {
    settings.hardware.nvidia.enable = lib.mkOption {
      type = lib.types.bool;
      description = ''
        Enable nvidia drivers
      '';
    };
  };

  config = mkIf cfg.enable {
    nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
      "nvidia-x11"
      "nvidia-settings"
    ];

    hardware.graphics.enable = true;

    services.xserver.videoDrivers = ["nvidia"]; # or "nvidiaLegacy470 etc.

    hardware.nvidia = {
      open = true;
      package = config.boot.kernelPackages.nvidiaPackages.beta;
    };
  };
}
