How to properly install NVIDIA drivers for hybrid graphics (Intel + NVIDIA 940MX) on NixOS?

Hi everyone,

I’m using NixOS on my MSI GL62 6QC 081TR laptop. It has hybrid graphics (Intel integrated GPU + NVIDIA GeForce 940MX). I’m a bit confused about how to properly set up the NVIDIA drivers in NixOS for this hybrid setup.

I’ve tried a few times in the past to set it up, but each time the system ends up stuck on a black screen and never boots into the graphical environment.

My questions are:

  1. Which NVIDIA driver package should I use for the 940MX on NixOS?
  2. Do I need to enable Bumblebee, PRIME, or anything else to make the hybrid graphics work properly?
  3. What should I add to my configuration.nix to get everything working?
  4. How do I make sure the system uses the Intel GPU by default and switches to NVIDIA when needed?

Any help, examples, or working configurations would be greatly appreciated!

Thanks in advance.

Quick code search (example via this topic) reveals configuration.nix - tokyob0t/dotfiles - Sourcegraph as a possible attempt you may try.

Here on the discourse are quite a lot topics regarding Intel / Nvidia hybrid - one of the most proactive people often helping out on that here even said they plan a better module to get through the whole Nvidia mess, for now in the wiki.nixos.org you should find info, Archlinux wiki as a last resort often has good info too.

What also often helps when posting questions are journalctl log snippets or in your case maybe X logs, configuration.nix you tried if you already have, again if unsure be encouraged to use the search function in the discourse, it often helps me and others to refine our questions towards a quicker solution.

2 Likes

In addition to the above, let me chime in on the specific questions:

If you check the version of the current package in nixpkgs stable, it’s 570.153.02 (may change, new versions have been released since, though until nvidia stop supporting your GPU you’ll be fine, and if nvidia do stop supporting it you likely won’t be hit until the next NixOS release).

You can use that number to find the supported GPUs here: Appendix A. Supported NVIDIA GPU Products

The 940MX is in that list, so you can safely leave the package option unset. All of the important wayland features have long since landed in the default driver, there is currently no reason to follow their beta branch for your average consumer.

As for the open (official, non-nouveau, recommended by nvidia) module, unfortunately that only supports Turing or newer, which the 940MX is not. This means some features will be missing: Chapter 44. Open Linux Kernel Modules

It also means you should set hardware.nvidia.open = false;.

Yes. Bumblebee is an ancient thing, ignore it. You need prime.

That said, I’d start with setting up just the nvidia driver. Once that’s confirmed to work, using prime is just a few tweaks away.

There is to my knowledge no adequate guide on making prime work with wayland yet, and as far as I know no DEs shipped with NixOS support X11 anymore.

To get it working in general, you need to do what these two modules do:

The code uses some neat nix features to be really generic, I’d be happy to translate that to something simpler if you tell us what desktop you’re running.

When set up, you then need to use the nvidia-offload utility to start any application you want to run on your discrete GPU (or use launchers and such that set the special environment variables for you).

Additionally, you probably want to enable dynamicBoost.

See the above. YMMV, if it doesn’t work, share your full configuration.

See above on prime.

2 Likes