X refuses to start with Proprietary Nvidia Drivers

Edit: I got the proprietary driver loaded. New problem: X doesn’t start.

I started using NixOS yesterday and I anticipated some trouble because I use an NVIDIA GPU. On Arch I switched to the proprietary driver; and it served me well with minimal trouble. On Nix, I sometimes see glitches, and more often than that, it just crashes. Looking at logs, I see Noveau. This is annoying because I went to the Nix Wiki and pasted in the snippet that should have enabled the proprietary drivers.

(Here)[System Crash log · GitHub] is my journalctl output after the crash.

Here’s also the output of neofetch

OS: NixOS 23.11.4761.5bf1cadb72ab (Tapir) x86_64 
Host: Dell Inc. 09KPNV 
Kernel: 6.1.79 
Uptime: 1 hour, 5 mins 
Packages: 853 (nix-system) 
Shell: bash 5.2.15 
Resolution: 1920x1080 
DE: none+i3 
WM: i3 
Theme: Breeze [GTK2/3] 
Icons: breeze [GTK2/3] 
Terminal: kitty 
Terminal Font: monospace 11.0 
CPU: Intel Xeon W3550 (4) @ 3.201GHz 
GPU: NVIDIA GeForce GTX 660 

And here’s the snippet from my config that should have enabled the correct drivers:

  # Load nvidia driver for Xorg and Wayland

  hardware.nvidia = {

    # Modesetting is required.
    modesetting.enable = true;

    # Nvidia power management. Experimental, and can cause sleep/suspend to fail.
    # Enable this if you have graphical corruption issues or application crashes after waking
    # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead 
    # of just the bare essentials.
    powerManagement.enable = false;

    # Fine-grained power management. Turns off GPU when not in use.
    # Experimental and only works on modern Nvidia GPUs (Turing or newer).
    powerManagement.finegrained = false;

    # Use the NVidia open source kernel module (not to be confused with the
    # independent third-party "nouveau" open source driver).
    # Support is limited to the Turing and later architectures. Full list of 
    # supported GPUs is at: 
    # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus 
    # Only available from driver 515.43.04+
    # Currently alpha-quality/buggy, so false is currently the recommended setting.
    open = false;

    # Enable the Nvidia settings menu,
	# accessible via `nvidia-settings`.
    nvidiaSettings = true;

    # Optionally, you may need to select the appropriate driver version for your specific GPU.
    package = config.boot.kernelPackages.nvidiaPackages.legacy_470;
  services.xserver.videoDrivers = ["nvidiaLegacy470"];

  # Enable OpenGL
  hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;

I don’t even know where to begin debugging this, so any help is appreciated.

Ok after checking lsmod, I have indeed confirmed that it is noveau being loaded not the proprietary driver. I think I have to modify kernel parameters, on Arch I simply removed the kms hook from mkinitcpio and installed the nvidia-utils package to prevent noveau from loading, how do I do the same thing here?

Did you try just [ "nvidia" ] here? I found this comment suggesting that the "nvidiaLegacy*" values are no longer valid, and there’s a lot of code in nixos/modules/hardware/video/nvidia.nix that is conditional on having "nvidia" as an element of that list (including the code that blacklists nouveau).

worth a shot I guess.

so what I ended up doing is blacklisting nouveau manually with boot.blacklistKernelModules and adding boot.extraModulePackages = [config.boot.kernelPackages.nvidiaPackages.legacy_470]; to my config.
I checked with lsmod and it now loads the proprietary driver!

New problem: X doesn’t start. Can’t find an error message either.

Turns out this was the last missing piece of the puzzle. Thanks for your help!

As a summary:
I had to add boot.extraModulePackages = [config.boot.kernelPackages.nvidiaPackages.legacy_470]; to my config as well as change services.xserver.videoDrivers to ["nvidia"] The blacklist for nouveau wasn’t necessary.