Troubleshooting - Failed Display Manager (any X11 DM or WM + LightDM + NVIDIA)

Summary

Problem Timeline & Diagnosis

Initial State: Display Manager Fails to Start

Investigation: Red Herrings

A series of errors were investigated that were symptoms of the deeper issue, but not the root cause.

Error 1: plymouth-quit.service not found

Diagnosis: LightDM was trying to communicate with the Plymouth boot splash screen, which wasn't enabled.
Fix: Added boot.plymouth.enable = true; to configuration.nix.

Error 2: Main process exited, code=exited, status=1/FAILURE

Diagnosis: LightDM was crashing instantly. This is often caused by a missing greeter (the login screen GUI).
Fix: Explicitly enabled the GTK greeter with services.xserver.displayManager.lightdm.greeters.gtk.enable = true;.

The True Root Cause: Xorg Driver Failure

Even after fixing the above, the service failed. The Xorg log provided the critical clue.

Critical Error from /var/log/Xorg.0.log

(EE) no devices detected
(EE) no screens found

Diagnosis: This is a fatal X server error. It means the kernel driver for the graphics card was not loaded or not functioning, so Xorg could not find any hardware to use.

The Turning Point: A Misleading Configuration

The investigation then focused on the NVIDIA driver configuration. A provided screenshot of hardware.nix contained the definitive, albeit misleading, clue.

The Misconfiguration

The configuration included a hardware.nvidia.prime block:

hardware.nvidia.prime = {
  offload.enable = true;
  # ...
};

This block is exclusively for dual-GPU systems (e.g., Optimus laptops) to manage switching between an integrated and a dedicated GPU. Its presence incorrectly led to the assumption that the hardware was a dual-GPU laptop.

Resolution

The actual hardware was a standard single-GPU desktop. The prime configuration was fundamentally incorrect for the machine.

Final Correct Configuration for Single-GPU NVIDIA Desktop

For a standard desktop with one NVIDIA GPU, the correct configuration combines three parts:
# /etc/nixos/configuration.nix
{ config, pkgs, ... }:

{
  # 1. Allow the proprietary NVIDIA driver to be installed
  nixpkgs.config.allowUnfree = true;

  # 2. Configure the X server to use the driver
  services.xserver = {
    enable = true;
    videoDrivers = [ "nvidia" ];
    displayManager.lightdm.enable = true;
    windowManager.i3.enable = true;
    # ... any other X server settings
  };

  # 3. Configure the NVIDIA kernel module itself
  hardware.nvidia = {
    # This enables the kernel module and is crucial for modern displays
    modesetting.enable = true;

    # Use the proprietary closed-source driver
    open = false;

    # Recommended for performance and power management
    powerManagement.enable = true;
  };
}