Screen flikering on NVIDIA x11

First time poster!! I’ve been running nixos for 1y ish and I’m so proud and happy of the current state of my machine!

Nonetheless I’ve been battling with nvidia drivers recently, I’m currently “just“ experiencing screen flickering from time to time. It’s a big win compared to previous generations in which I was not even able to get into graphical session but still a headache..

May somebody point me towards the issue of the flickering XOR give me tips for maybe improving my config? Thanks ^^

Machine hardware:

Asus Rog Strix G513QR with a rtx 3070 and ryzen 7 5800 H

Machine software:

Kernel: 6.12.74

Nvidia driver Version: 580.119.02

Nixos 25.11

Possibly useful snippets from my configuration.nix:

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

boot.kernelParams = [
  “nvidia_drm.modeset=1”
  # “nvidia_drm.fbdev=1”
  # “pcie_aspm=off”
  “zswap.enabled=1”
  # “nvidia.NVreg_DynamicPowerManagement=0x02”
  “iommu=pt”
];
boot.kernelPackages = pkgs.linuxPackages;

My nvidia.nix module (imported at the configuration.nix):

{
config,
pkgs,
lib,
…
}:
{
services.xserver = {
  enable = true;
  videoDrivers = [
    “amdgpu”
    “nvidia”
  ];
};

hardware.nvidia = {
  package = config.boot.kernelPackages.nvidiaPackages.stable;

  modesetting.enable = true;

  powerManagement = {
    enable = false;
    finegrained = false;
  };

  open = true;
  nvidiaSettings = true;

  prime = {
    sync.enable = true;
    amdgpuBusId = "PCI:1:0:0";
    nvidiaBusId = "PCI:5:0:0";
  };
};

hardware.nvidia-container-toolkit.enable = true;
hardware.opengl.enable = true;

specialisation.on-the-go.configuration = {
  system.nixos.tags = [ “on-the-go” ];

  hardware.nvidia.prime = {
    offload = {
      enable = lib.mkForce true;
      enableOffloadCmd = lib.mkForce true;
    };
  sync.enable = lib.mkForce false;
  };
};
}

lshw -c display (as the wiki says) gives me this:
*-display
description: amdgpudrmfb
product: nvidia-drmdrmfb
physical id: 0
bus info: pci@0000:01:00.0
logical name: /dev/fb1
logical name: /dev/fb0
version: a1
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress bus_master cap_list rom fb
configuration: depth=32 driver=nvidia latency=0 mode=3840x2160 resolution=3840,2160 visual=truecolor xres=3840 yres=2160
resources: iomemory:fc0-fbf iomemory:fe0-fdf irq:44 memory:fb000000-fbffffff memory:fc00000000-fdffffffff memory:fe00000000-fe01ffffff ioport:f000(size=128) memory:fc000000-fc07ffff
*-display
product: amdgpudrmfb
physical id: 0
bus info: pci@0000:05:00.0
logical name: /dev/fb0
version: c5
width: 64 bits
clock: 33MHz
capabilities: pm pciexpress msi msix bus_master cap_list fb
configuration: depth=32 driver=amdgpu latency=0 resolution=1920,1080
resources: iomemory:fe0-fdf iomemory:fe0-fdf irq:56 memory:fe10000000-fe1fffffff memory:fe20000000-fe201fffff ioport:d000(size=256) memory:fc500000-fc57ffff

Notice that in my nvidia module I have PCI:5:0:0 for nvidia and PCI:1:0:0 for amd. They’re reversed but swear it’s the only way I’ve managed xrandr to show both amd and nvidia in –listproviders.

Providers: number : 2
Provider 0: id: 0x54 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 4 outputs: 2 associated providers: 1 name:AMD Radeon Graphics @ pci:0000:05:00.0
Provider 1: id: 0x218 cap: 0x2, Sink Output crtcs: 4 outputs: 2 associated providers: 1 name:NVIDIA-G0

Thanks for reading!

So, I made this thread a while ago: Can we solve the nvidia situation?

Still working on a solution, but what you’re sharing here is the exact reason I made that thread :wink: The configuration is confusing and everybody is cargo culting from either other people who don’t know what they’re doing or people with different hardware, resulting in quite broken setups.

To my knowledge, your configuration should look like this (I’ll just assume you’re using wayland). Note that I expect you to delete every single line of code you’ve shared, including all the kernel params - sharing the rest of your config so we can spot other things you shouldn’t be doing may be helpful:

{
  services.xserver.videoDrivers = [ "nvidia" ];

  hardware.nvidia = {
    open = true;

    # Stable uses an outdated nvidia driver, which
    # sadly still has the old sleep service, but this
    # should not matter much in practice.
    #
    # I *intended* to recommend setting up the new
    # feature yourself, but NixOS 26.05 actually does
    # this correctly, so let's stick to this.
    powermanagement.enable = true;

    # The finegrained option on the other hand is an
    # affront, you *should* configure those udev rules
    # manually.
  };
}

Most of the other stuff either shouldn’t be enabled in the first place, or we should revisit it when things are working.

Kernel suspend notifiers are not supported by the 580 driver version they are using. The required driver 595 is the default on unstable and NixOS 26.05, and you don’t need to set the kernel option manually, it’s already set by the Nvidia module when powerManagement.enable = true; is set.

1 Like

Yep, I also just clocked that I forgot to add the package override. I checked the 25.11 source which doesn’t have the kernel option set yet, but indeed, switching to unstable configures this correctly.

Well thanks for the post u wrote, it did make me have a better insight of current nvidia situation.

Regards my setup, it’s now a bit clearer that I’ve made kind of mess by trying to apply too many patches. I’m not running wayland but actually awesomewm, and I don’t have picom.

Possibly relevants parts of my configuration.nix:

{ config, pkgs, inputs, … }:

let
  unstable = import inputs.nixpkgs-unstable {
  config.allowUnfree = true;
};
in
{
imports = [
  ./hardware-configuration.nix
  ./nvidia.nix
];

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

boot.kernelParams = [
  “nvidia_drm.modeset=1”
  “zswap.enabled=1”
  “iommu=pt”
];

boot.kernelPackages = pkgs.linuxPackages;

services.xserver = {
  enable = true;
  xkb = {
    layout = “es”;
  };
  windowManager.awesome.enable = true;
  displayManager.startx.enable = true;
};

services.ollama = {
  enable = true;
  acceleration = “cuda”;
  package = unstable.ollama-cuda;
};

environment.variables = {
  OLLAMA_FLASH_ATTENTION = “true”;
};

nixpkgs.config.allowUnfree = true;
nix.settings.experimental-features = [ “nix-command” “flakes” ];

xdg.portal = {
  enable = true;
  xdgOpenUsePortal = true;
  extraPortals = [
    pkgs.xdg-desktop-portal-gtk
  ];
  config.common.default = [ “gtk” ];
};

  system.stateVersion = “25.05”;
}

This is as well my .xinitrc:

export XDG_CURRENT_DESKTOP=awesome
export XDG_SESSION_DESKTOP=awesome
export XDG_SESSION_TYPE=x11

dbus-update-activation-environment --systemd DISPLAY XAUTHORITY XDG_CURRENT_DESKTOP

exec dbus-run-session awesome

I don’t know what else could I share to pinpoint the possible root of the flickering (let me know I’ll share it).

Thanks in bfhand!

It’d still be nice if you could try my suggestion, even if you eventually want to go back to a prime setup and using cuda. I’m not suggesting this aimlessly, simplifying first helps.

Also, do remove every mention of nvidia in your configuration.nix. They’re superfluous.

If you still get flickering when using only the nvidia GPU and only for rendering, you’ll have to contact nvidia support. But usually not turning every possible knob does resolve things for people.

1 Like

I’ve been tinkering a bit these days and managed to untangle some things and tangle some others.

I’m facing something similar to this user:

Firstly, I’ve imported this nixos-hardware config at my configuration.nix.

Looks like this:

{
  imports = [
    ../../../common/cpu/amd
    ../../../common/cpu/amd/pstate.nix
    ../../../common/gpu/nvidia
    ../../../common/gpu/nvidia/prime.nix
    ../../../common/gpu/nvidia/ampere
    ../../../common/pc/laptop
    ../../../common/pc/ssd
    ../../battery.nix
  ];
  #these ids are correct to my machine
  hardware.nvidia.prime = {
    amdgpuBusId = “PCI:05:00:0”;
    nvidiaBusId = “PCI:01:00:0”;
  };
}

Which itself pulls ../../../common/gpu/nvidia/default.nix:

{ lib, ... }:
{  services.xserver.videoDrivers = lib.mkDefault [ "nvidia" ]; }

../../../common/gpu/nvidia/prime.nix:

{ lib, config, ... }:
{
  imports = [ ./. ];
  options = {
    hardware.nvidia.primeBatterySaverSpecialisation = lib.mkEnableOption "configure a specialisation which turns on NVIDIA Prime battery saver";
  };
  config = {
    hardware.nvidia.prime = {
      offload = {
        enable = lib.mkOverride 990 true;
        enableOffloadCmd = lib.mkIf config.hardware.nvidia.prime.offload.enable true; # Provides `nvidia-offload` command.
      };
      # Hardware should specify the bus ID for intel/nvidia devices
    };
    specialisation = lib.mkIf config.hardware.nvidia.primeBatterySaverSpecialisation {
      battery-saver.configuration = {
        system.nixos.tags = [ "battery-saver" ];
        imports = [
          # Leave only the integrated GPU enabled
          ./disable.nix
        ];
        hardware.nvidia = {
          prime.offload.enable = lib.mkForce false;
          powerManagement = {
            enable = lib.mkForce false;
            finegrained = lib.mkForce false;
          };
        };
      };
    };
  };
}

And ../../../common/gpu/nvidia/ampere/default.nix between other not so relevant to this topic files( I think)

{ lib, config, ... }:
let
  nvidiaPackage = config.hardware.nvidia.package;
in
{
  imports = [ ../. ];
  # enable the open source drivers if the package supports it
  hardware.nvidia.open = lib.mkOverride 990 (nvidiaPackage ? open && nvidiaPackage ? firmware);
}

Then I have this custom nvidia.nix module of my config where I explicitly try to force Sync Mode from the previously mentioned asus rog nixos-hardware.

{
  lib,
  config,
  pkgs,
  ...
}:
{
  hardware.nvidia = {
    #Added this to avoid GPU going idle 
    powerManagement = {
      finegrained = lib.mkForce false;
      enable = lib.mkForce true;
    };
    #I think this is redundant
    modesetting.enable = lib.mkForce true;
  };

  hardware.nvidia.prime = {
    #Added this to enable sync and remove offload
    sync.enable = lib.mkForce true;
    offload.enable = lib.mkForce false;
    offload.enableOffloadCmd = lib.mkForce false;
  };
  services.xserver.enable = true;
  #Added this according to https://wiki.nixos.org/wiki/NVIDIA but ideally I'd like to start graphical session with startx
  # displayManager.startx.enable = true;
  services.xserver.displayManager.lightdm.enable = true;

}

This is the glxinfo -B output:

glx: failed to create dri3 screen
failed to load driver: nouveau
samba@samba:~/ > glxinfo -B 
name of display: :0
glx: failed to create dri3 screen
failed to load driver: nouveau
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: Mesa (0xffffffff)
    Device: llvmpipe (LLVM 19.1.7, 256 bits) (0xffffffff)
    Version: 25.0.7
    Accelerated: no
    Video memory: 31509MB
    Unified memory: yes
    Preferred profile: core (0x1)
    Max core profile version: 4.5
    Max compat profile version: 4.5
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.2
Memory info (GL_ATI_meminfo):
    VBO free memory - total: 31 MB, largest block: 31 MB
    VBO free aux. memory - total: 25459 MB, largest block: 25459 MB
    Texture free memory - total: 31 MB, largest block: 31 MB
    Texture free aux. memory - total: 25459 MB, largest block: 25459 MB
    Renderbuffer free memory - total: 31 MB, largest block: 31 MB
    Renderbuffer free aux. memory - total: 25459 MB, largest block: 25459 MB
Memory info (GL_NVX_gpu_memory_info):
    Dedicated video memory: 405477 MB
    Total available memory: 436987 MB
    Currently available dedicated video memory: 31 MB
OpenGL vendor string: Mesa
OpenGL renderer string: llvmpipe (LLVM 19.1.7, 256 bits)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 25.0.7
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile

OpenGL version string: 4.5 (Compatibility Profile) Mesa 25.0.7
OpenGL shading language version string: 4.50
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile

OpenGL ES profile version string: OpenGL ES 3.2 Mesa 25.0.7
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20

I have now removed the nvidia kernelParams due the suggestion of @TLATER since they are redundant too.

These are some possibly relevant xorg logs cat .local/share/xorg/Xorg.0.log | grep -E -i “nvidia|nouveau|glx”

[    42.842] Kernel command line: initrd=\EFI\nixos\5ay5v27dnka7kiki4bawxp2pph6qfq62-initrd-linux-6.12.63-initrd.efi init=/nix/store/4zvdww1wxgn8z6kf1fpla6l4zsfzgszy-nixos-system-samba-25.05.20260102.ac62194/init amd_pstate=active zswap.enabled=1 iommu=pt i2c_hid.polling_interval=0 loglevel=4 lsm=landlock,yama,bpf nvidia-drm.modeset=1 nvidia-drm.fbdev=1 nvidia.NVreg_PreserveVideoMemoryAllocations=1 nvidia.NVreg_OpenRmEnableUnsupportedGpus=1
[    42.845] (**) |-->Screen "Screen-nvidia[0]" (0)
[    42.845] (**) |   |-->Device "Device-nvidia[0]"
[    42.845] (==) No monitor specified for screen "Screen-nvidia[0]".
[    42.853] (**) ModulePath set to "/nix/store/i68swddsbcdkn34cc7xnc4l8xfmh95bz-xf86-video-amdgpu-23.0.0/lib/xorg/modules,/nix/store/4wjwpwd6dk3yv8pjhd4ma3m55hwnajrg-nvidia-x11-570.195.03-6.12.63-bin/lib/xorg/modules,/nix/store/f9nyq02plppm68j3w5if3sb7ndk7s45w-xorg-server-21.1.20/lib/xorg/modules,/nix/store/zaw3g17n2r7p0qpls8p02l71k9brvw4j-xf86-input-evdev-2.11.0/lib/xorg/modules,/nix/store/m566lnbn44fkizbx6hz2b2ag8yz2s8xb-xf86-input-wacom-1.2.3/lib/xorg/modules,/nix/store/xjgpgdq9i9m8pym1k7wf0zjf2ijzi5wl-xf86-input-libinput-1.5.0/lib/xorg/modules"
[    42.867] (II) "glx" will be loaded by default.
[    42.867] (II) LoadModule: "glx"
[    42.871] (II) Loading /nix/store/f9nyq02plppm68j3w5if3sb7ndk7s45w-xorg-server-21.1.20/lib/xorg/modules/extensions/libglx.so
[    42.877] (II) Module glx: vendor="X.Org Foundation"
[    42.877] (II) LoadModule: "nvidia"
[    42.877] (II) Loading /nix/store/4wjwpwd6dk3yv8pjhd4ma3m55hwnajrg-nvidia-x11-570.195.03-6.12.63-bin/lib/xorg/modules/drivers/nvidia_drv.so
[    42.881] (II) Module nvidia: vendor="NVIDIA Corporation"
[    42.884] (II) NVIDIA dlloader X Driver  570.195.03  Sat Sep 20 00:39:17 UTC 2025
[    42.884] (II) NVIDIA Unified Driver for all Supported NVIDIA GPUs
[    42.890] (II) NVIDIA(0): Creating default Display subsection in Screen section
	"Screen-nvidia[0]" for depth/fbbpp 24/32
[    42.890] (==) NVIDIA(0): Depth 24, (==) framebuffer bpp 32
[    42.890] (==) NVIDIA(0): RGB weight 888
[    42.890] (==) NVIDIA(0): Default visual is TrueColor
[    42.890] (==) NVIDIA(0): Using gamma correction (1.0, 1.0, 1.0)
[    42.890] (**) NVIDIA(0): Option "AllowEmptyInitialConfiguration"
[    42.890] (**) NVIDIA(0): Option "SidebandSocketPath" "/run/nvidia-xdriver/"
[    42.890] (**) NVIDIA(0): Enabling 2D acceleration
[    42.890] (II) Loading sub module "glxserver_nvidia"
[    42.890] (II) LoadModule: "glxserver_nvidia"
[    42.891] (II) Loading /nix/store/4wjwpwd6dk3yv8pjhd4ma3m55hwnajrg-nvidia-x11-570.195.03-6.12.63-bin/lib/xorg/modules/extensions/libglxserver_nvidia.so
[    42.980] (II) Module glxserver_nvidia: vendor="NVIDIA Corporation"
[    42.980] (II) NVIDIA GLX Module  570.195.03  Sat Sep 20 00:38:46 UTC 2025
[    42.981] (II) NVIDIA: The X server supports PRIME Render Offload.
[    42.988] (--) NVIDIA(0): Valid display device(s) on GPU-0 at PCI:1:0:0
[    42.988] (--) NVIDIA(0):     DFP-0
[    42.988] (--) NVIDIA(0):     DFP-1
[    43.008] (II) NVIDIA(0): NVIDIA GPU NVIDIA GeForce RTX 3070 Laptop GPU (GA104-A) at
[    43.008] (II) NVIDIA(0):     PCI:1:0:0 (GPU-0)
[    43.008] (--) NVIDIA(0): Memory: 8388608 kBytes
[    43.008] (--) NVIDIA(0): VideoBIOS: 94.04.3e.00.a1
[    43.008] (II) NVIDIA(0): Detected PCI Express Link width: 16X
[    43.009] (--) NVIDIA(GPU-0): DFP-0: disconnected
[    43.009] (--) NVIDIA(GPU-0): DFP-0: Internal DisplayPort
[    43.009] (--) NVIDIA(GPU-0): DFP-0: 2670.0 MHz maximum pixel clock
[    43.009] (--) NVIDIA(GPU-0): 
[    43.009] (--) NVIDIA(GPU-0): DFP-1: disconnected
[    43.009] (--) NVIDIA(GPU-0): DFP-1: Internal TMDS
[    43.009] (--) NVIDIA(GPU-0): DFP-1: 165.0 MHz maximum pixel clock
[    43.009] (--) NVIDIA(GPU-0): 
[    43.009] (==) NVIDIA(0): 
[    43.009] (==) NVIDIA(0): No modes were requested; the default mode "nvidia-auto-select"
[    43.009] (==) NVIDIA(0):     will be used as the requested mode.
[    43.009] (==) NVIDIA(0): 
[    43.009] (--) NVIDIA(0): No enabled display devices found; starting anyway because
[    43.009] (--) NVIDIA(0):     AllowEmptyInitialConfiguration is enabled
[    43.017] (II) NVIDIA(0): Validated MetaModes:
[    43.017] (II) NVIDIA(0):     "NULL"
[    43.017] (II) NVIDIA(0): Virtual screen size determined to be 640 x 480
[    43.017] (WW) NVIDIA(0): Unable to get display device for DPI computation.
[    43.017] (==) NVIDIA(0): DPI set to (75, 75); computed from built-in default
[    43.256] (II) AMDGPU(G0): glamor: Using OpenGL 4.6 context.
[    43.263] (II) NVIDIA: Reserving 24576.00 MB of virtual memory for indirect memory
[    43.263] (II) NVIDIA:     access.
[    43.284] (WW) NVIDIA(0): ACPI: failed to determine the system's current power source
[    43.311] (II) NVIDIA(0): Setting mode "NULL"
[    43.377] (==) NVIDIA(0): Disabling shared memory pixmaps
[    43.377] (==) NVIDIA(0): Backing store enabled
[    43.377] (==) NVIDIA(0): Silken mouse enabled
[    43.377] (==) NVIDIA(0): DPMS enabled
[    43.377] (WW) NVIDIA(0): Option "DRI" is not used
[    43.377] (WW) NVIDIA(0): Option "RandRRotation" is not used
[    43.377] (II) NVIDIA(0): [DRI2] Setup complete
[    43.377] (II) NVIDIA(0): [DRI2]   VDPAU driver: nvidia
[    43.425] (II) Initializing extension GLX
[    43.439] (II) IGLX: Loaded and initialized swrast
[    43.439] (II) GLX: Initialized DRISWRAST GL provider for screen 0
[    43.439] (II) Initializing extension GLX
[    43.439] (II) Indirect GLX disabled.
[    43.439] (II) GLX: Another vendor is already registered for screen 0
[    43.439] (II) Initializing extension NV-GLX
[    43.627] (II) config/udev: Adding input device HDA NVidia HDMI/DP,pcm=3 (/dev/input/event11)
[    43.627] (II) config/udev: Adding input device HDA NVidia HDMI/DP,pcm=7 (/dev/input/event12)
[    43.628] (II) config/udev: Adding input device HDA NVidia HDMI/DP,pcm=8 (/dev/input/event13)
[    43.628] (II) config/udev: Adding input device HDA NVidia HDMI/DP,pcm=9 (/dev/input/event14)
[    51.871] (--) NVIDIA(GPU-0): DFP-0: disconnected
[    51.871] (--) NVIDIA(GPU-0): DFP-0: Internal DisplayPort
[    51.871] (--) NVIDIA(GPU-0): DFP-0: 2670.0 MHz maximum pixel clock
[    51.871] (--) NVIDIA(GPU-0): 
[    51.873] (--) NVIDIA(GPU-0): DFP-1: disconnected
[    51.873] (--) NVIDIA(GPU-0): DFP-1: Internal TMDS
[    51.873] (--) NVIDIA(GPU-0): DFP-1: 165.0 MHz maximum pixel clock
[    51.873] (--) NVIDIA(GPU-0): 
[    51.896] (II) NVIDIA(0): Setting mode "NULL"
[    51.911] (WW) NVIDIA(0): ACPI: failed to determine the system's current power source
[    66.248] (--) NVIDIA(GPU-0): DFP-0: disconnected
[    66.248] (--) NVIDIA(GPU-0): DFP-0: Internal DisplayPort
[    66.248] (--) NVIDIA(GPU-0): DFP-0: 2670.0 MHz maximum pixel clock
[    66.248] (--) NVIDIA(GPU-0): 
[    66.251] (--) NVIDIA(GPU-0): DFP-1: disconnected
[    66.251] (--) NVIDIA(GPU-0): DFP-1: Internal TMDS
[    66.251] (--) NVIDIA(GPU-0): DFP-1: 165.0 MHz maximum pixel clock
[    66.251] (--) NVIDIA(GPU-0): 
[    66.291] (II) NVIDIA(0): Setting mode "NULL"
[    66.306] (WW) NVIDIA(0): ACPI: failed to determine the system's current power source
[    73.188] (II) NVIDIA(GPU-0): Deleting GPU-0

Any ideas of how could I correctly configure the sync profile on this AMD+NVIDIA x11 laptop?

Seems like it’s not detecting any monitors. Sounds to me like sync mode simply doesn’t work on your hardware, you’d have to check with asus or nvidia support.

Try connecting an external display?

I do have 2 monitors always connected and both are working, one is a 4k monitor connected to a usb-c that plugs directly to the gpu and the other is a regular 1080 plugged via HDMI.

xrandr:
Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767
DP-0 connected primary (normal left inverted right x axis y axis)
3840x2160 60.00 + 29.98
eDP-1-0 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 344mm x 194mm
1920x1080 300.00*+ 60.00 +
HDMI-A-1-0 connected (normal left inverted right x axis y axis)
1920x1080 60.00 + 60.00 50.00 50.00 59.94 30.00 24.00 29.97 23.98

In case anybody want’s to glaze at my config: