NVIDIA/Bumblebee

This is a guide to configuring a Gentoo system to make use of Hybrid Graphics using:
 * The proprietary Nvidia graphics drivers
 * The open source modesetting Intel/i915/i965 drivers
 * Bumblebee
 * bbswitch for hardware switching
 * Primus for bridging

This configuration prefers Primus over Optirun/VGL.

NVIDIA Optimus Support
This is pretty much straightforward. If you have an intel processor (2nd Gen +) and a NVIDIA gpu, then you probably have optimus on your laptop. To check for sure, run

and look for VGA or 3D controllers to see your present GPUs. If you don't have an optimus system, this guide will do nothing for you.

Nvidia Drivers
First configure your system to use Nvidia's proprietary drivers over the open source Nouveau Drivers and install the drivers. This is already detailed elsewhere on the wiki and is not repeated here.

Kernel
Ensure that you system can load and unload modules:

Video Cards
Set your video card variables like so:

USE Flags
In order to allow easy enabling and disabling of the nvidia drivers, we need to disable the  and   USE flags for the nvidia drivers:

Now update your @world set:

Then reboot your system

Installing Bumblebee, bbswitch, Primus
Emerge the packages:

User access to Bumblebee
Make sure to add your user to the  and   groups to allow use of bumblebee:

(Replacing USER with your username)

Configuring /etc/init.d/bumblebee
By default, the OpenRC bumblebee module is set to depend on VGL and XDM. We are using primus over VGL. The XDM dependancy can cause problems if this configuration is being setup prior to the x server. Remove the following lines (which should be near the start of the file):

Your final file should look something like this:

The important part is that it no longer has any dependencies.

Configuring /etc/bumblebee/bumblebee.conf
The following settings need to be present in the /etc/bumblebee/bumblebee.conf file.

OpenRC
Now enable bumblebe to load at runlevel

And once again, reboot the system:

=== Configuring /etc/modprobe.d/nvidia-rmmod.conf Earlier, we disabled the  and   USE flags for the Nvidia drivers. This means we should only have the module  present and not ,  , or. In order that  functions correctly, we need it to remove only   and nothing else. Remove all other modules from /etc/modprobe.d/nvidia-rmmod.conf so that it changes from looking like this:

to this:

Using glxgears
Install the  package to access  :

Before we run our test, make sure the  is NOT loaded:

And check the status of bbswitch using:

As you can see:
 * bbswitch is loaded
 * nvidia is NOT loaded
 * the nvidia GPU (at PCI location 01:00.0) is OFF

Now let’s check if the NVIDIA card will be switched ON and the nvidia module will be loaded once optirun/primusrun are executed, and if it’ll switch OFF and the nvidia module will be unloaded once optirun/primusrun finish executing. From within an Xorg Session:

or (but not both at once):

A window showing glxgears should open. While it's running, check:

This shows that the Nvidia GPU is now on, its module loaded, and openGL is using it as expected. Once you end the  or   command and exit glxgears, the previous checks run again should show the GPU off and the module unloaded.

Using glxinfo
Alternatively,  can be used to see if bumblebee is working (Pipe the commands to grep to see the displayed output):

As you can see, running the command without  runs with the iGPU but with   runs with the Nvidia GPU.