Need some help getting NVIDIA working properly

Hey everyone, I have a Thinkpad P50 with an Nvidia Quadro M1000M, but only my internal display is recognized. I tried following the wiki and some configs on the forum here, but none of them work for me. What am I doing wrong? If I remove “modesetting” my screen just stays black. No problems on Ubuntu, I can check which driver is currently being used there if needed.

$ lspci| grep -E 'VGA|3D'
00:02.0 VGA compatible controller: Intel Corporation HD Graphics 530 (rev 06)
01:00.0 VGA compatible controller: NVIDIA Corporation GM107GLM [Quadro M1000M] (rev a2)
$ xrandr --listproviders
Providers: number : 1
Provider 0: id: 0x43 cap: 0x2, Sink Output crtcs: 3 outputs: 1 associated providers: 0 name:modesetting
$ nvidia-smi
Thu Jul 23 21:46:01 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.100      Driver Version: 440.100      CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Quadro M1000M       Off  | 00000000:01:00.0  On |                  N/A |
| N/A   39C    P8    N/A /  N/A |     34MiB /  2002MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1009      G   ...9frkddk0y5qqa2-xorg-server-1.20.8/bin/X    31MiB |
+-----------------------------------------------------------------------------+
$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.4.52, NixOS, 20.03.2611.bb8f0cc2279 (Markhor)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.6`
 - channels(bobe): `"home-manager-20.03"`
 - channels(root): `"nixos-20.03.2611.bb8f0cc2279, nixos-hardware"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

configuration.nix:

  services.xserver.videoDrivers = [ "nvidia" "modesetting" ];
  hardware.nvidia = {
    optimus_prime = {
      enable = true;
      nvidiaBusId = "PCI:1:0:0";
      intelBusId = "PCI:0:2:0";
    };
    modesetting.enable = true;
  };

  services.xserver = {
    enable = true;
    
    displayManager = {
      startx.enable = true;
    };
  };
$ glxinfo | grep "OpenGL renderer"
Error: couldn't find RGB GLX visual or fbconfig
Error: couldn't find RGB GLX visual or fbconfig

journalctl -b: journalctl_b.log - Google Drive

interesting topic as my laptop@work is a P50 as well; but it’s not allowed to install any Linux variant

I had checked the options and found: hardware.bumblebee.connectDisplay

Perhaps it’s worth a try. Got it from: NixOS Search

Thank you for your suggestion. Unfortunately it does not seem to work; I set both connectDisplay to true and added bumblebee to the video driver list (both separately and simultaneously), but no changes. I guess I should have a look at that bumblebee flag’s source for more hints.

Can you try remove “modesetting” from services.xserver.videoDrivers and set modesettings.enable = false

That did the trick, thank you very much! I could swear I’ve tried this configuration already before, but I guess other stuff was broken then. I guess another change that I should mention that happened since I started this thread is that I now use a display manager (the nixos default, which I think is lightdm? Not sure), whereas before I used startx. This might be a piece of the puzzle (as the docs for hardware.nvidia.optimus_prime.enable mention that this is needed).

The only problem now is that the fonts in my login screen and other UI elements is very tiny. But I guess I’ll have to fix that with plain configuration.

Hi, did you ever get external monitors working? I followed this thread to get my own P50 working well, but when connected to an external monitor - the monitor is detected, but just flickers on/off and never shows a display.

Here is my configuration file for my P50 for reference sake.

 config, lib, pkgs, ... }:

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

  hardware.nvidia = {
    optimus_prime = {
      enable = true;
      nvidiaBusId = "PCI:1:0:0";
      intelBusId = "PCI:0:2:0";
    };
    modesetting.enable = false;
  };
}

I never had problems with external monitors I think - will doublecheck this for you. For completeness, this is in my config now:

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

hardware = {
 nvidia = {
   optimus_prime = {
     enable = true;
     nvidiaBusId = "PCI:1:0:0";
     intelBusId = "PCI:0:2:0";
   };
 };
 
 opengl = {
   driSupport = true;
   driSupport32Bit = true;
 };
};

services.xserver = {
 enable = true;
 
 displayManager = {
   session = [
     {
       name = "home-manager";
       start = ''
         ${pkgs.runtimeShell} $HOME/.hm-xsession &
         waitPID=$!
       '';
       manage = "window";
     }
   ];
 };
};

Seems like our configs are almost identical now. I wasn’t using a display manager before, which can also cause problems (I think I read this on the wiki somewhere), not sure if this applies to you. I’m also not sure if the opengl part is needed.

EDIT: Well, I had to fiddle a bit with panning through xrandr, but my display seems to work fine on both the laptop’s own HDMI ports, as well as the HDMI ports on my docking station. I can give you more config info if you want (I’m on 20.03, but besides that there’s not that much stuff in my config, probably because I don’t use nixos daily (yet)), but then you need to tell me where to look. There also doesn’t seem to be nvidia related stuff in my hardware.config:

# Do not modify this file!  It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations.  Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, ... }:

{
  imports =
    [ <nixpkgs/nixos/modules/installer/scan/not-detected.nix>
    ];

  boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usb_storage" "usbhid" "sd_mod" "rtsx_pci_sdmmc" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-intel" ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/redacted";
      fsType = "ext4";
    };

  swapDevices =
    [ { device = "/dev/disk/by-uuid/redacted"; }
    ];

  nix.maxJobs = lib.mkDefault 8;
  powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
}