Sway nvidia flickering

I recently started using NixOS on a Lenovo X1 extreme laptop with an Intel and a Nvidia graphic card. Preferably I want to use Sway as tiling window manager. When I attach an external monitor with HDMI cable I experience flickering. It seems similar to what @nomadics describe here and is indeed very annoying.

As I am using Sway instead of Hyprland (both are built on Wayland) I decided to create a new topic instead of commenting on the topic linked above. However I suspect, these issues are related, and this could be an issue with the nvidia graphic card driver - but I am reaching the edge of my current knowledge here and will appreciate any further help.

Temporarily I have switched to Gnome that also runs on xorg. Here I do not experience any flickering on the external monitor.

Graphic card info:

$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Alder Lake-P Integrated Graphics Controller (rev 0c)
01:00.0 VGA compatible controller: NVIDIA Corporation GA107M [GeForce RTX 3050 Ti Mobile] (rev a1)

$ lcpci | less
/VGA
00:02.0 VGA compatible controller: Intel Corporation Alder Lake-P Integrated Graphics Controller (rev 0c) (prog-if 00 [VGA controller])
        Subsystem: Lenovo Device 22f8
        Flags: bus master, fast devsel, latency 0, IRQ 189, IOMMU group 0
        Memory at 625b000000 (64-bit, non-prefetchable) [size=16M]
        Memory at 4000000000 (64-bit, prefetchable) [size=512M]
        I/O ports at 4000 [size=64]
        Expansion ROM at 000c0000 [virtual] [disabled] [size=128K]
        Capabilities: <access denied>
        Kernel driver in use: i915
        Kernel modules: i915
01:00.0 VGA compatible controller: NVIDIA Corporation GA107M [GeForce RTX 3050 Ti Mobile] (rev a1) (prog-if 00 [VGA controller])
        Subsystem: Lenovo Device 22f8
        Flags: bus master, fast devsel, latency 0, IRQ 190, IOMMU group 16
        Memory at b3000000 (32-bit, non-prefetchable) [size=16M]
        Memory at 6000000000 (64-bit, prefetchable) [size=8G]
        Memory at 6200000000 (64-bit, prefetchable) [size=32M]
        I/O ports at 3000 [size=128]
        Expansion ROM at b4080000 [virtual] [disabled] [size=512K]
        Capabilities: <access denied>
        Kernel driver in use: nvidia
        Kernel modules: nvidiafb, nouveau, nvidia_drm, nvidia

System info:

$ nix-info -m
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.39, NixOS, 23.11 (Tapir), 23.11.20230724.b12803b`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.15.1`
 - channels(root): `"nixos-23.05"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Relevant snippets from configuration.nix regarding nvidia and sway installation:

  environment.loginShellInit = ''
    if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
          sway --unsupported-gpu -V > .sway-log 2>&1
    fi
  '';

  nixpkgs.config.allowUnfree = true;

  hardware.nvidia = {
    package = config.boot.kernelPackages.nvidiaPackages.stable;
    nvidiaPersistenced = true;
    modesetting.enable = true;
    prime = {
      sync.enable = true;
      nvidiaBusId = "PCI:1:0:0";
      intelBusId = "PCI:0:2:0";
    };
  };

  services.xserver = {
    enable = true;
    videoDrivers = [
      "nvidia"
    ];
  };

  programs.sway = {
    enable = true;
    wrapperFeatures.gtk = true;
    extraPackages = with pkgs; [
      linux-firmware
      swaylock
      swayidle
      alacritty
      i3status-rust
      brightnessctl
      wayland
    ];
    extraSessionCommands = ''
      export MOZ_ENABLE_WAYLAND=1
      export WLR_DRM_NO_MODIFIERS=1
      export WLR_DRM_DEVICES=/dev/dri/card0
    '';
  };

Wlroots does not support the nvidia drivers (nor does sway for that matter). The hyprland wiki has some notes on potential fixes, it may involve patching wlroots: Nvidia | Hyprland Wiki

YMMV, given you’re using a different compositor altogether.

1 Like

Yes, I did try to patch wlroots as well, however it did not help. The flickering continues.

The patch I tried out was this, which is the same patch as suggested in method 1 , for fixing random flickering in the link you suggested

I fixed the flickering on sway + nvidia via export WLR_RENDERER=vulkan and

  hardware.opengl.extraPackages = with pkgs; [
    # trying to fix `WLR_RENDERER=vulkan sway`
    vulkan-validation-layers 
  ];
2 Likes

Hmm, thanks for the suggestion. I have tried it out and here is what I found:

External monitor gets inactive (before DP-7 ‘Samsung’ was in the active state). Flickering continues - however this time the flickering is on the inbuilt monitor eDP-1.

output from $ swaymsg -t get_outputs:

Output eDP-1 'BOE 0x0AE0 Unknown' (focused)

(...)

Output DP-7 'Samsung Electric Company LC49G95T H1AK500000' (inactive)

I am happy to hear the vulkan trick , helped in your case. Unfortunately it did not work on my hardware

The new nvidia driver has some fixes that might be of interest to you: Linux x64 (AMD64/EM64T) Display Driver | 535.98 | Linux 64-bit | NVIDIA

Wow - thanks for the tip, I will try it out and let you know how it worked.

Indeed sounds promising

@eska did you have any luck with this? Same symptoms here, down to enabling the vulkan backend disabling the external monitor and making the internal one start flickering instead.

I am having the same problem. Have you found a solution?

Hi all,

Unfortunately i did not find a solution - yet.

I have switched to using only external monitor and the flickering issue persist when using sway.

Currently thinking to adopt i3 in my work flow, but it seems a little like moving back instead of moving forward?

Any help with this is much welcome!