{
  pkgs,
  config,
  lib,
  ...
}:
{
  environment = {
    etc."libva.conf".text = ''
      LIBVA_MESSAGING_LEVEL=1
    '';
    systemPackages = builtins.attrValues {
      inherit (pkgs) ddcutil;
    };
    sessionVariables = {
      MOZ_DISABLE_RDD_SANDBOX = 1;
      LIBVA_DRIVER_NAME = "nvidia";
    };
    variables = {
      GBM_BACKEND = "nvidia-drm";
      __GLX_VENDOR_LIBRARY_NAME = "nvidia";
      NIZOS_OZONE_WL = "1";
      KWIN_DRM_ALLOW_NVIDIA_COLORSPACE = "1";
      ENABLE_HDR_WSI = "1";
    };
  };
  hardware = {
    graphics = {
      enable = true;
      enable32Bit = true;
      extraPackages = builtins.attrValues {
        inherit (pkgs) nvidia-vaapi-driver libva-vdpau-driver;
      };
      extraPackages32 = builtins.attrValues {
        inherit (pkgs.pkgsi686Linux) nvidia-vaapi-driver libva-vdpau-driver;
      };
    };
    nvidia = {
      modesetting.enable = true;
      forceFullCompositionPipeline = false;
      nvidiaSettings = true;
      open = true;
      gsp.enable = true;
      package = config.boot.kernelPackages.nvidiaPackages.latest;
      powerManagement = {
        enable = true;
        finegrained = false;
      };
    };
  };
  services = {
    xserver = {
      enable = true;
      videoDrivers = [ "nvidia" ];
    };
  };
  hardware.nvidia-container-toolkit.enable = lib.mkIf config.virtualisation.docker.enable true;
}
