NVIDIA driver problems

Hi all.

I’m trying to get my HVIDIA card to work with NixOS.

I’ve made the following observations:

  • without enabling the graphics driver, the system boots to gnome, no problem
  • with the graphics driver enabled, the system boots up and I can SSH into
    the machine, but the display doesn’t receive any input
  • doesn’t matter if I blacklist the amdgpu module, display won’t receive any input from the card
  • even with GDM and Gnome disabled (but NVIDIA drivers left enabled), the display still doesn’t work
  • the journalctl --boot output doesn’t show anything that seems problematic to me
  • it doesn’t matter what options are set in hardware.nvidia
  • switching to a different driver package (from beta or unstable) doesn’t change the result

I’m not sure where I can properly debug this issue. My feeling says that it might be the X server, but the log doesn’t show any conclusive error. At the end is just says that X server was properly shut down. I’ve tried several tips I’ve found in several threads in this forum but none of them helped.

Here you can find relevant log files:

Here’s my config:

{
  config,
  lib,
  pkgs,
  ...
}: let
  user = "f44";

  # us, de, uk, ...
  keymap = "us";
in {
  imports = [
    # Include the results of the hardware scan.
    ../hardware_configs/obox.nix
  ];

  boot = {
    loader = {
      # generic-extlinux-compatible.enable = true
      systemd-boot.enable = true;
      efi.canTouchEfiVariables = true;
    };

    # interferes with NVIDIA driver
    kernelParams = ["module_blacklist=amdgpu"];
  };

  virtualisation.vmVariant = {
    # following configuration is added only when building VM with build-vm
    virtualisation = {
      memorySize = 2048; # Use 2048MiB memory.
      diskSize = 10240;
      cores = 3;
      graphics = true;
    };
  };

  nix.extraOptions = "experimental-features = nix-command flakes";

  # Enable cross compiling for ARM;
  # https://github.com/nix-community/nixos-generators/tree/master?tab=readme-ov-file#cross-compiling
  boot.binfmt.emulatedSystems = ["aarch64-linux"];

  networking = {
    networkmanager.enable = true;
    hostName = "obox";
  };

  nixpkgs.config = {
    allowUnfree = true;
    cudaSupport = true;
  };

  # Set your time zone.
  time.timeZone = "Europe/Berlin";

  # Select internationalization properties.
  i18n.defaultLocale = "de_DE.utf8";

  i18n.extraLocaleSettings = {
    LC_ADDRESS = "de_DE.UTF-8";
    LC_IDENTIFICATION = "de_DE.UTF-8";
    LC_MEASUREMENT = "de_DE.UTF-8";
    LC_MONETARY = "de_DE.UTF-8";
    LC_NAME = "de_DE.UTF-8";
    LC_NUMERIC = "de_DE.UTF-8";
    LC_PAPER = "de_DE.UTF-8";
    LC_TELEPHONE = "de_DE.UTF-8";
    LC_TIME = "de_DE.UTF-8";
  };

  # Configure console keymap
  console.keyMap = keymap;

  # https://github.com/NixOS/nixpkgs/issues/224332
  # https://github.com/NixOS/nixpkgs/issues/232286
  # https://discourse.nixos.org/t/removing-the-amdgpu-module-from-the-kernel/32374
  # https://discourse.nixos.org/t/sddm-fails-to-launch/51469/9
  # https://discourse.nixos.org/t/nvidia-the-bane-of-my-existence/51524/7
  hardware = {
    pulseaudio.enable = false;
    bluetooth = {
      enable = true; # enables support for Bluetooth
      powerOnBoot = true; # powers up the default Bluetooth controller on boot
    };

    graphics = {
      enable = true;
    };

    nvidia = {
      modesetting.enable = true;
      open = false;
      # Allow headless mode
      nvidiaPersistenced = true;
      powerManagement.enable = true;
    };
  };

  security.rtkit.enable = true;

  services = {
    udev.packages = with pkgs; [gnome-settings-daemon];
    pipewire = {
      enable = true;
      alsa.enable = true;
      alsa.support32Bit = true;
      pulse.enable = true;
      jack.enable = true;
      wireplumber.enable = true;
    };
    blueman.enable = true;

    # X11 and LXDE
    xserver = {
      enable = true;
      displayManager.gdm.enable = true;
      desktopManager.gnome.enable = true;
      videoDrivers = ["nvidia"];
    };

    qemuGuest.enable = true;
  };

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users = {
    ${user} = {
      isNormalUser = true;
      description = user;
      extraGroups = ["networkmanager" "wheel"];
      shell = pkgs.nushell;
      openssh.authorizedKeys.keys = [
        "..."
      ];
      hashedPassword = "...";
    };
  };

  home-manager.users = {
    # Main user
    ${user} = {pkgs, ...}: {
      # Allow unfree packages
      nixpkgs.config.allowUnfree = true;
      home.packages = with pkgs; [
        firefox
        just
      ];

      programs = {
        zoxide = {
          enable = true;
          enableNushellIntegration = true;
        };
      };
    };
  };

  services = {
    udisks2 = {
      enable = true;
      mountOnMedia = true;
    };
    devmon.enable = true;
    gvfs.enable = true;

    gnome = {
      # Enable gnome-keyring to store passwords.
      # E.g. allows VScode to store credentials locally after logging in to GitHub.
      gnome-keyring.enable = true;
      # core-utilities.enable = false;
    };
  };

  fonts.packages = with pkgs; [
    noto-fonts
    noto-fonts-cjk-sans
    noto-fonts-emoji
    (nerdfonts.override {fonts = ["FiraCode" "Hack"];})
  ];

  programs = {
    dconf.enable = true;
    gamemode.enable = true;
    steam = {
      enable = true;
      gamescopeSession.enable = true;
    };
  };

  networking.firewall.allowedTCPPorts = [
  ];
  networking.firewall.allowedUDPPorts = [
  ];

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "24.05"; # Did you read the comment?
  # system.autoUpgrade.enable = true;

  # garbage collect
  nix = {
    settings.auto-optimise-store = true;
    gc = {
      automatic = true;
      dates = "weekly";
      options = "delete-older-than 7d";
    };
  };
}