Help Getting NVIDIA gpu working on Dell XPS 15 9560

Hi there,
I am trying to get my NVIDIA gpu working on my laptop with hybrid graphics. I have a Dell XPS 15 9560. I looked in the nixos-hardware repository (nixos-hardware/dell/xps/15-9560 at master · NixOS/nixos-hardware · GitHub), but I still can’t get it working. Here is the relevant bits of my configuration.nix:

{
  imports =
    [ # Include the results of the hardware scan.
      <nixos-hardware/dell/xps/15-9560>
      ./hardware-configuration.nix
    ];

...

###### Nvidia Nonsense ######

  # enable opengpl and gpu drivers
    hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };

  services.xserver.videoDrivers = ["nvidia"];

  hardware.nvidia.modesetting.enable = true;

    hardware.nvidia.prime = {
    offload = {
      enable = true;
      enableOffloadCmd = true;
    };

    # integrated
    intelBusId = "PCI:0:2:0";
    
    # dedicated
    nvidiaBusId = "PCI:1:0:0";
  };

  # specialisation = {
  #   gaming-time.configuration = {

  #     hardware.nvidia = {
  #       prime.sync.enable = lib.mkForce true;
  #       prime.offload = {
  #         enable = lib.mkForce false;
  #         enableOffloadCmd = lib.mkForce false;
  #       };
  #     };
  #   };
  # };

  # Taken from NixOS wiki: 
  # If you encounter the problem of booting to text mode you 
  # might try adding the Nvidia kernel module manually with: 
  # boot.initrd.kernelModules = [ "nvidia" ];
  # boot.extraModulePackages = [ config.boot.kernelPackages.nvidia_x11 ];

###### End  Nvidia Nonsense ######

I have commented out some of the stuff that didn’t work.

What is very strange is that when I look for PCI devices with lspci or lshw, the nvidia gpu does not appear. However, I know that the nvidia gpu is working properly, because when I boot into windows it works fine! When I initially set this up, I swear I remember the nvidia gpu appearing as a "3D" device under lspci, but now it’s gone…

Any help would be very much appreciated!

Hi @liamwb,
I’m exactly in the same boat as you, installed NixOS on my XPS and trying to get the GPU working.

The problem is that the nixos-hardware module for the xps 9560 completely disables the nvidia gpu!

This was done 5 months ago because of broken bumblebee:

One of the option is to enable the Nvidia GPU only with <nixos-hardware/dell/xps/15-9560/nvidia>.

I will try to check if bumblebee is still broken (and I suspect it is, since there are no commits for that package on nixpkgs) or if we can re-enable the old configuration

Well now I feel silly! I had been following this Vimjoyer tutorial, which now seems to work straightforwardly. Both nvidia-offload and the dedicated-gpu “gaming-time” specialization seem to work.

I was under the impression that bumblebee has more or less been superseded by prime, so should we update the nixos-hardware entry to use that? Here’s what currently seems to be working in my configuration:

###### Nvidia Nonsense ######

  # enable opengpl and gpu drivers
    hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };

  services.xserver.videoDrivers = ["nvidia"];

  hardware.nvidia.modesetting.enable = true;

    hardware.nvidia.prime = {
    offload = {
      enable = true;
      enableOffloadCmd = true;
    };

    # integrated
    intelBusId = "PCI:0:2:0";
    
    # dedicated
    nvidiaBusId = "PCI:1:0:0";
  };

  specialisation = {
    dGPU.configuration = {

      hardware.nvidia = {
        prime.sync.enable = lib.mkForce true;
        prime.offload = {
          enable = lib.mkForce false;
          enableOffloadCmd = lib.mkForce false;
        };
      };
    };
  };

###### End  Nvidia Nonsense ######

We should also probably include the sync specialization somewhere (I have not tested this one yet):

 hardware.nvidia.prime = {
    sync.enable = true;

    # integrated
    intelBusId =  "PCI:0:2:0";

    # dedicated
    nvidiaBusId = "PCI:1:0:0";
  };

What do you think?

You’re right, prime offload is the way to go!

This will definitely be a good contribution to nixos-hardware, feel free to submit a PR!

I’ll test it myself ASAP

Not sure about the sync specialization to be part of nixos-hardware… maybe a separate config in the gpu/nvidia folder (if it’s not already there), so that one can choose to enable it in addition to the base config?

EDIT: the <nixos-hardware/dell/xps/15-9560/nvidia> mentioned before already has prime offload enabled, so you can just use that.

I took a deeper look at the nixos-hardware configuration, and the only things missing are the opengl and modesetting blocks, so you can use

{
  imports = [
    <nixos-hardware/dell/xps/15-9560/nvidia>
    ./hardware-configuration.nix
  ];

  hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };
  hardware.nvidia.modesetting.enable = true;
}

and that’s it.
Of course you can also add the specialisation thing if you want the sync/offload choice at boot

I use the nvidia module along with a couple other options to use prime offload on wayland. Works well when I need it. It is off when I do not, I have it in it’s own specialisation.

1 Like

I got some strange behavior with this configuration: when I unplug the power cord, the pc freezes for a bit and restarts itself :worried:
I can’t see anything strange with journalctl, so I’m not sure what’s going on.
Do you ever experienced something like that?

I just tested the nvidia configuration and I did not encounter any strange behavior like that. It appears to work properly, although there are some odd missing fields when I run nvidia-smi, but that might be correct behaviour:

+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.78                 Driver Version: 550.78         CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce GTX 1050        Off |   00000000:01:00.0 Off |                  N/A |
| N/A   52C    P8             N/A / ERR!  |     140MiB /   4096MiB |     36%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                         
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A      6082      G   ./runner                                      138MiB |
+-----------------------------------------------------------------------------------------+

What is odd is that the comments in the nvidia/default.nix claim that it disables the intel gpu:

  # This runs only nvidia, great for games or heavy use of render applications

  ##### disable intel, run nvidia only and as default
  hardware.nvidia.prime = {
    # Bus ID of the Intel GPU.
    intelBusId = "PCI:0:2:0";

    # Bus ID of the NVIDIA GPU.
    nvidiaBusId = "PCI:1:0:0";
  };
}

But I can’t see where in the imports or the body of the file that the intel gpu is being disabled, and indeed when I run nvtop the intel gpu appears, and reports utilization as well. Maybe I’m misunderstanding the comment, but it seems misleading?

I believe this is because the intel card is still needed, since it’s the one directly connected to the display/hdmi (and the reason why we can’t use the nvidia card to do video passthrough to windows vms, but that’s another story)

1 Like