Problem with Wayland after nvidia install and configuration(kinda)

I’m not so long on NixOS, for a long time I studied it on a virtual machine where everything was fine, today I decided to switch to this system, but after setting nvidia I don’t run most of the programs, I opened the console via ctrl+alt+f2 and looked there journalctl where it was written for example for blackbox:

blackbox-wrapp[2648]: Error 71 (Protocol error) dispatching to Wayland display.

Here are my configs:
configuration.nix

{ config, pkgs, ... }:

{
  imports =
    [
      ./hardware-configuration.nix
    ];

  nix.settings.experimental-features = [ "nix-command" "flakes" ];

  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  networking.hostName = "nixos"; # Define your hostname.

  networking.networkmanager.enable = true;

  time.timeZone = "Europe/Moscow";

  i18n.defaultLocale = "ru_RU.UTF-8";

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

  services.xserver.enable = true;

  services.xserver.displayManager.gdm.enable = true;
  services.xserver.desktopManager.gnome.enable = true;
  services.xserver.displayManager.gdm.wayland = true;

  services.xserver.xkb = {
    layout = "us";
    variant = "";
  };

  # Enable sound with pipewire.
  hardware.pulseaudio.enable = false;
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
  };

  users.users.inari = {
    isNormalUser = true;
    description = "Maxim";
    extraGroups = [ "networkmanager" "wheel" ];
    shell = pkgs.fish;
  };
  programs.fish.enable = true;

  nixpkgs.config.allowUnfree = true;

  environment.systemPackages = with pkgs; [
    home-manager
    zed-editor
    blackbox-terminal
    nixd
    nautilus
    nautilus-open-in-blackbox
    heroic
    gnome-tweaks
    protonup

    zen-browser

    gnomeExtensions.dash-to-dock
    gnomeExtensions.blur-my-shell
    gnomeExtensions.appindicator
    gnomeExtensions.vitals
    gnomeExtensions.gsconnect
    gnomeExtensions.clipboard-indicator
    gnomeExtensions.rounded-window-corners-reborn
  ];

  programs.steam.enable = true;
  programs.steam.gamescopeSession.enable = true;
  programs.gamemode.enable = true;

   environment.sessionVariables = {
      STEAM_EXTRA_COMPAT_TOOLS_PATHS = "/home/inari/.steam/root/compatibilitytools.d";
   };

  nixpkgs.config.packageOverrides = pkgs: {
    zen-browser = pkgs.callPackage ./nonNixPackages/zen-browser/default.nix { };
  };

  fonts.packages = with pkgs; [
    jetbrains-mono
  ];

  services.gnome.core-utilities.enable = false;
  environment.gnome.excludePackages = [ pkgs.gnome-tour ];
  services.xserver.excludePackages = [ pkgs.xterm ];
  services.xserver.desktopManager.xterm.enable = false;
  documentation.nixos.enable = false;
  programs.nano.enable = false;

  system.stateVersion = "24.05"; # Did you read the comment?

}

hardware-configuration

{ config, lib, pkgs, modulesPath, ... }:

{
  imports =
    [ (modulesPath + "/installer/scan/not-detected.nix")
    ];

  boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "uas" "usb_storage" "sd_mod" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-amd" ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/78657e37-f633-480f-9ff6-1172f749eacc";
      fsType = "ext4";
    };

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/AA5A-6F14";
      fsType = "vfat";
      options = [ "fmask=0077" "dmask=0077" ];
    };

  swapDevices =
    [ { device = "/dev/disk/by-uuid/f294c9c7-b577-4ec6-9bad-e6b7111773d6"; }
    ];

  networking.useDHCP = lib.mkDefault true;

  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;

  hardware.graphics.enable = true;
  hardware.graphics.enable32Bit = true;

  services.xserver.videoDrivers = ["nvidia"];
  hardware.nvidia.modesetting.enable = true;

  hardware.nvidia.open = false;

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

   amdgpuBusId = "PCI:5:0:0";
   nvidiaBusId = "PCI:1:0:0";
 };
}

In some instances, the Nvidia drivers need to be early-loaded in order to function properly. Try setting this and see if it makes any difference:

boot.initrd.kernelModules = [ "nvidia" "nvidia_modeset" "nvidia_drm" "nvidia_uvm" ];

Hi, thanks for the advice but unfortunately it didn’t help, it might help that I have a laptop with an AMD integrated graphics card and an NVIDIA discrete one

Did you reboot after making the change? If yes, you can try setting these environment variables since Gnome has a known issue with Wayland that forces the dedicated GPU to be used by default, so you can at least open the applications with your integrated GPU if the issue is with Nvidia.

  environment.variables = {
    # Use integrated GPU for gnome-shell
    # See https://gitlab.gnome.org/GNOME/mutter/-/issues/2969
    __EGL_VENDOR_LIBRARY_FILENAMES = "${pkgs.mesa.drivers}/share/glvnd/egl_vendor.d/50_mesa.json";
    __GLX_VENDOR_LIBRARY_NAME = "mesa";
  };

Don’t forget to reboot after this as well.

And that didn’t help, maybe I can provide you with some logs?

In the other thread, you mentioned you were using X11, does everything work there?

Sure, you can share the system log if you want or some snippets you think are most relevant to the issue.

Yes, everything works fine in X11

Can you please tell me what logs would help you and how I can find them?

Interesting…

The first parts of journalctl -b 0 usually contain any driver-loading problems. Try searching for keywords like nvidia, amd and error.

I’ve seen several errors in gnome-shell for example:

.gnome-shell-wr[1933]: WL: error in client ncommunication (pid 7751)

There were also errors when trying to run blackbox, which I’ve already written about:

Does running GSK_RENDERER=gl blackbox work?

If yes, the issue is most likely related to Applications (gnome related possibly) don't work after update · Issue #353990 · NixOS/nixpkgs · GitHub which has been fixed in the beta Nvidia drivers.

If you’re on NixOS 24.11+, you can use them with:

hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.beta;

Or if you’re still on 24.05:

hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.mkDriver {
  version = "565.57.01"; # beta
  sha256_64bit = "sha256-buvpTlheOF6IBPWnQVLfQUiHv4GcwhvZW3Ks0PsYLHo=";
  sha256_aarch64 = "sha256-aDVc3sNTG4O3y+vKW87mw+i9AqXCY29GVqEIUlsvYfE=";
  openSha256 = "sha256-/tM3n9huz1MTE6KKtTCBglBMBGGL/GOHi5ZSUag4zXA=";
  settingsSha256 = "sha256-H7uEe34LdmUFcMcS6bz7sbpYhg9zPCb/5AmZZFTx1QA=";
  persistencedSha256 = "sha256-hdszsACWNqkCh8G4VBNitDT85gk9gJe1BlQ8LdrYIkg=";
};

If GSK_RENDERER=gl did not work, if might be worth it to try the beta drivers anyways as they might have better Wayland support.

2 Likes

Thank you so much, that really helped.

1 Like