{ config, pkgs, lib, ... }:
let
  cfg = config.my;
in
{
  config = lib.mkIf cfg.nvidia.enable {
    services.xserver.videoDrivers = lib.optionals cfg.nvidia.enable ["nvidia"];
    hardware.nvidia = {
      modesetting.enable = true;
      powerManagement.enable = true;
      powerManagement.finegrained = false;
      open = true;
      nvidiaSettings = cfg.desktop.enable;
      # Optionally, you may need to select the appropriate driver version for your specific GPU.
      package = config.boot.kernelPackages.nvidiaPackages.stable;
    };
    hardware.nvidia-container-toolkit.enable = config.virtualisation.docker.enable;
    environment.systemPackages = with pkgs; [
      nvidia_oc
      nvidia-vaapi-driver
    ]
    ++ lib.optionals config.virtualisation.docker.enable [
      nvidia-docker
      nvidia-container-toolkit
    ];
  };
}
