Razer Blade 15 Nvidia + Integrated Graphics on NixOS Issues

I currently have a Razer Blade 15 Advanced Model (Early 2020) and have been struggling to get my Nvidia graphics working properly with the i915 driver.

I have tried multiple configuration options as outlined in the Nvidia NixOS Wiki Page but have had no luck. The Nvidia card seems to have exclusive control over the USB-C ports so as I result I have tried multiple configurations using Prime’s sync mode.

When I enable the Nvidia card, my laptop screen goes black once I login via GDM. I’ve seen the note about blacklisting the i915 driver but that prevents my laptop screen from working properly. But when my integrated graphics card/laptop screen are functioning that prevents the external display ports from working properly.

So it seems I’m in a situation where I have to choose between either the integrated graphics or the Nvidia graphics. What do I need to change in order to have both functioning?

Here’s my config (the comments contain a bunch of other things I have tried): https://github.com/heywoodlh/nixpkgs/blob/0296b13bc8fcf88f4b24583c5e854a083f3fa9d6/workstation/razer-blade-15.nix

To use the laptop screen (and NVIDIA PRIME offload rendering):

To use the NVIDIA driver as an RandR 1.4 output source provider, also known as “PRIME”, the X server needs to be configured to use the NVIDIA driver for its primary screen and to use the “modesetting” driver for the other graphics device.

Section "ServerLayout"
    Identifier "layout"
    Screen 0 "nvidia"
    Inactive "intel"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "<BusID for NVIDIA device here>"
EndSection

Section "Screen"
    Identifier "nvidia"
    Device "nvidia"
    Option "AllowEmptyInitialConfiguration"
EndSection

Section "Device"
    Identifier "intel"
    Driver "modesetting"
EndSection

Section "Screen"
    Identifier "intel"
    Device "intel"
EndSection

To use the laptop screen and any screen connected to the NVIDIA GPU:

To use the NVIDIA driver as an RandR 1.4 output sink provider, also known as “Reverse PRIME”, the X server needs to be configured to use the “modesetting” driver for its primary screen and to use the NVIDIA driver for the other graphics device.

This is what’s being worked on in nvidia: Add Reverse Prime Sync by GoogleBot42 · Pull Request #165188 · NixOS/nixpkgs · GitHub

Section "ServerLayout"
    Identifier "layout"
    Screen 0 "intel"
    Inactive "nvidia"
    Option "AllowNVIDIAGPUScreens"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
EndSection

Section "Screen"
    Identifier "nvidia"
    Device "nvidia"
EndSection

Section "Device"
    Identifier "intel"
    Driver "modesetting"
    BusID "<BusID for Intel device here>"
EndSection

Section "Screen"
    Identifier "intel"
    Device "intel"
EndSection

Source: Chapter 33. Offloading Graphics Display with RandR 1.4

2 Likes

Thanks for the response! So I’ve tried using the XServer snippets in your response and mixing certain NixOS configuration options but I still seem to have no luck getting both the laptop and GPU displays to work at the same time.

With Reverse PRIME, is there any way that I can implement it now? Or do I just have to wait until that PR is merged into a release?

Here’s my current config using your second snippet for my X config related to Reverse PRIME: https://github.com/heywoodlh/nixpkgs/blob/18e0b3914db5cd93483e95df823c03363141e54a/workstation/razer-blade-15.nix

This results in my laptop display working but not the displays connected to the GPU.

My Nix skills are a bit light so if an example NixOS config/snippet could be provided for me to look at I would really appreciate it!

Additionally, with my current config it seems like the drivers are being assigned to the cards correctly:

  *-display
       physical id: 0
       bus info: pci@0000:01:00.0
       version: a1
       width: 64 bits
       clock: 33MHz
       capabilities: bus_master cap_list rom
       configuration: driver=nvidia latency=0
       resources: iomemory:600-5ff iomemory:600-5ff irq:186 memory:a3000000-a3ffffff memory:6030000000-603fffffff memory:6040000000-6041ffffff ioport:3000(size=128) memory:a4000000-a407ffff
  *-display
       physical id: 2
       bus info: pci@0000:00:02.0
       version: 05
       width: 64 bits
       clock: 33MHz
       capabilities: bus_master cap_list rom
       configuration: driver=i915 latency=0
       resources: iomemory:600-5ff iomemory:400-3ff irq:184 memory:6043000000-6043ffffff memory:4000000000-400fffffff ioport:4000(size=64) memory:c0000-dffff

I got Reverse Prime working with the following:

sudo nix-channel --add https://github.com/GoogleBot42/nixpkgs/archive/refs/heads/master.tar.gz nvidia-reverse-prime

And then I used the following config:

This results in my laptop display working properly and external displays (connected to the Nvidia GPU) sort of working. The displays only work if I do not have them connected on boot and if I connect them when I’m on the GDM login screen. If I connect them during boot or after I have logged into GNOME, then my X server crashes.

After I login to GNOME, my external display is black and I have to run the following commands to mirror my laptop display:

xrandr --setprovideroutputsource NVIDIA-G0 modesetting && \
xrandr --auto && \
xrandr --fb 4480x1440 --output eDP-1 --mode 1920x1200 --pos 2560x0

This is some progress but it would be ideal for Xorg to not be so easy to crash – although from reading it seems to be an upstream issue with Nvidia/Xorg.

I would appreciate any additional suggestions on how to make my Reverse Prime setup more stable.

I have a similar setup to yours, on a Lenovo Thinkpad P1. I’ve found one workaround to the X crashes on monitor disconnect was to suspend first, then unplug.

sudo systemctl suspend

When using sync mode, you can run something similar to your above Xrandr to get both external and laptop monitors working:

xrandr --setprovideroutputsource modesetting NVIDIA-0 && \
  xrandr --auto   && \
  xrandr --fb 4480x1440 --output eDP-1-1 --mode 1920x1200 --pos 2560x0 --output HDMI-0 --pos 0x0 --primary
dconf write /org/gnome/desktop/interface/text-scaling-factor 1

Also, you probably saw this already, but the wiki has a helpful tip on creating “specialisations” for boot menu items, so you can switch easily between sync, offload, etc: Nvidia - NixOS Wiki

Finally, your laptop may have a BIOS controlled mux switch to drive the internal display off the dGPU – maybe that would let you run in sync mode and connect / disconnect monitors without suspend.

Good luck!

I did not even think to check the BIOS settings! I set GPU MODE to “Dedicated GPU only” in my BIOS and used sync mode and that got all my issues ironed out (aside from the fact that sync mode is more battery intensive, of course):

Here’s my config for my Razer Blade 15 using Sync mode (both the laptop display and external displays are working now):