Hibernate/Suspend with Nvidia Drivers on Gentoo

The proprietary Nvidia drivers from x11-drivers/nvidia-drivers contain the closed-sources drivers from Nvidia for Linux. On my laptop, the current version show problems when hibernating/suspending. Several people found that the resume operations do not properly bring up the X-sessions. The same problem occurs on my GTX 1060 laptop. None of the helpful tips found on the Internet would allow me to hibernate/resume when the drivers are loaded.

The only solution that worked for me, is to unload the drivers before going into hibernate and to load them after the resume operation is completed. If you configured your hibernate using this tutorial, and are using sys-power/pm-utils and sys-power/upower-pm-utils, then you can place the following script in /etc/pm/sleep.d/ to unload and load the drivers:

# 01nvidia_drivers: unloads and loads nvidia drivers before and after suspend operations

function unload_if_loaded() {
    if lsmod | grep "$MODULE" &>/dev/null; then
        rmmod $MODULE

case "$1" in
       unload_if_loaded nvidia_drm
       unload_if_loaded nvidia_modeset
       unload_if_loaded nvidia
       modprobe nvidia_drm
   *) exit $NA

You can place the script to /etc/pm/sleep.d/01nvidia_drivers and make sure it is executable.

chmod +x /etc/pm/sleep.d/01nvidia_drivers

Afterwards, you should be able to hibernate/resume properly.