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