Nvidia legacy 390 driver wont build with kernel 5.4

I’m having trouble configuring my nvidia card, which is an nvidia gtx 550 ti. it should use the legacy 390 driver, i believe.
in my current configuration, without specifying the kernel version, it builds, but the performance is very bad, so im trying to use the kernel version 5.4, which i believe is better with those older cards, but my configuration isnt building.
The kernel 5.4 builds if i dont put nvidia configuration. and the performance gets better than using the newer kernel with nvidia driver. but i want to see if the performance gets better with kernel v 5.4 and nvidia driver.

relevant configurantion:

  nixpkgs.config.nvidia.acceptLicense = true;
  services.xserver.videoDrivers = [ "nvidia" ];
  
  hardware.nvidia = {
    modesetting.enable = true;
    open = false;
    nvidiaSettings = true;
    package = config.boot.kernelPackages.nvidiaPackages.legacy_390;
    powerManagement.enable = false;
  };

  boot.kernelPackages = pkgs.linuxPackages_5_4;

build error log:

/build/NVIDIA-Linux-x86_64-390.157/kernel/nvidia-drm/nvidia-drm-connector.c: In function '__nv_drm_connector_detect_internal':
/build/NVIDIA-Linux-x86_64-390.157/kernel/nvidia-drm/nvidia-drm-connector.c:192:66: error: macro "drm_connector_for_each_possible_encoder" requires 3 arguments, but only 2 given
  192 |     nv_drm_connector_for_each_possible_encoder(connector, encoder) {
      |                                                                  ^
In file included from /nix/store/1jfwss71fyvz6mx4m4zzi296l4jv4496-linux-5.4.294-dev/lib/modules/5.4.294/source/include/drm/drm_modes.h:33,
                 from /nix/store/1jfwss71fyvz6mx4m4zzi296l4jv4496-linux-5.4.294-dev/lib/modules/5.4.294/source/include/drm/drm_crtc.h:40,
                 from /nix/store/1jfwss71fyvz6mx4m4zzi296l4jv4496-linux-5.4.294-dev/lib/modules/5.4.294/source/include/drm/drmP.h:68,
                 from /build/NVIDIA-Linux-x86_64-390.157/kernel/nvidia-drm/nvidia-drm-helper.h:31,
                 from /build/NVIDIA-Linux-x86_64-390.157/kernel/nvidia-drm/nvidia-drm-connector.c:29:
/nix/store/1jfwss71fyvz6mx4m4zzi296l4jv4496-linux-5.4.294-dev/lib/modules/5.4.294/source/include/drm/drm_connector.h:1613:9: note: macro "drm_connector_for_each_possible_encoder" defined here
 1613 | #define drm_connector_for_each_possible_encoder(connector, encoder, __i) \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/build/NVIDIA-Linux-x86_64-390.157/kernel/nvidia-drm/nvidia-drm-helper.h:382:5: error: 'drm_connector_for_each_possible_encoder' undeclared (first use in this function); did you mean 'drm_connector_has_possible_encoder'?
  382 |     drm_connector_for_each_possible_encoder(connector, encoder)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/build/NVIDIA-Linux-x86_64-390.157/kernel/nvidia-drm/nvidia-drm-connector.c:192:5: note: in expansion of macro 'nv_drm_connector_for_each_possible_encoder'
  192 |     nv_drm_connector_for_each_possible_encoder(connector, encoder) {
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/build/NVIDIA-Linux-x86_64-390.157/kernel/nvidia-drm/nvidia-drm-helper.h:382:5: note: each undeclared identifier is reported only once for each function it appears in
  382 |     drm_connector_for_each_possible_encoder(connector, encoder)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/build/NVIDIA-Linux-x86_64-390.157/kernel/nvidia-drm/nvidia-drm-connector.c:192:5: note: in expansion of macro 'nv_drm_connector_for_each_possible_encoder'
  192 |     nv_drm_connector_for_each_possible_encoder(connector, encoder) {
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/build/NVIDIA-Linux-x86_64-390.157/kernel/nvidia-drm/nvidia-drm-connector.c:192:68: error: expected ';' before '{' token
  192 |     nv_drm_connector_for_each_possible_encoder(connector, encoder) {
      |                                                                    ^
/build/NVIDIA-Linux-x86_64-390.157/kernel/nvidia-drm/nvidia-drm-connector.c:174:25: warning: unused variable 'encoder' []
  174 |     struct drm_encoder *encoder;
      |                         ^~~~~~~
make[3]: *** [/nix/store/1jfwss71fyvz6mx4m4zzi296l4jv4496-linux-5.4.294-dev/lib/modules/5.4.294/source/scripts/Makefile.build:262: /build/NVIDIA-Linux-x86_64-390.157/kernel/nvidia-drm/nvidia-drm-connector.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [/nix/store/1jfwss71fyvz6mx4m4zzi296l4jv4496-linux-5.4.294-dev/lib/modules/5.4.294/source/Makefile:1770: /build/NVIDIA-Linux-x86_64-390.157/kernel] Error 2
make[1]: *** [Makefile:186: sub-make] Error 2
make[1]: Leaving directory '/nix/store/1jfwss71fyvz6mx4m4zzi296l4jv4496-linux-5.4.294-dev/lib/modules/5.4.294/source'
make: *** [Makefile:81: modules] Error 2
error: builder for '/nix/store/8m3hdkbyfhymi75nfyjnrkb2srg2a4ak-nvidia-x11-390.157-5.4.294.drv' failed with exit code 2
error: 1 dependencies of derivation '/nix/store/pcx140k82d8qcqqzrih3md68arfvsh3a-etc.drv' failed to build
error: 1 dependencies of derivation '/nix/store/81kh4144rh5knx8j5mbl39sw00jg0fjg-linux-5.4.294-modules.drv' failed to build
error: 1 dependencies of derivation '/nix/store/cpfngn8nysih3yrbrwydg2rrpmxhmk4v-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/s938k1qrgfrqziz968pwjlb165cyjspw-nixos-system-nixos-25.05.804936.a676066377a2.drv' failed to build

System info:

[gabriel@nixos:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.12.35, NixOS, 25.05 (Warbler), 25.05.805252.b43c397f6c21`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.28.3`
 - channels(root): `"nixos-25.05"`
 - nixpkgs: `/nix/store/q0b32kq4djk8iz4bs93hkz3ldrnbvfbb-nixos-25.05/nixos`

Evidently the nvidia driver cannot even compile against that kernel, where did you get that idea from?

The nvidia driver is a 3rd party kernel module, which means it’s code that is developed as if it was part of the kernel source code, but it isn’t actually part of the kernel source code.

This means that if the kernel sources change, parts of them may change in ways that make the nvidia driver no longer call the right function names and such. At that point, you cannot compile the nvidia driver against that kernel, and someone has to update the driver.

For this reason, when using nvidia you should never change the kernel version from the default.

Since nvidia no longer support the 390 driver, this likely means it will never work on newer kernels.

3rd parties develop patches for the driver, which nixpkgs applies - this is why the driver works at all. You could try to find a patch for the kernel version you’d like to use, but this is setting your computer on fire territory if you don’t know what you’re doing.

Nouveau is a better bet in the long term, but ironically for older cards it likely never will perform well. I find it interesting that you say the performance is better without the nvidia driver - this likely either means your iGPU is better than your nvidia card or it’s a placebo.

Edit: hrrrm, upstream appears to add a patch to fix this, does it work with any other kernel versions?

Nope, you’re trying 5.4, not 6.4. Nixpkgs doesn’t carry a patch for that, nor does arch. It’s unlikely to have a significant impact anyway, this is probably gamer folklore. I wouldn’t pursue this further.

Thanks for the answer, I didnt know nvidia driver was that much connected to a kernel version.

I actually tried kernel version 6.6 with nvidia and it actually build. but the performance was the same as 6.12.

I actually got better performance with the version 5.4 but not in my iGpu but using nouveau with my nvidia card. But it is rather confuse:

  • with nouveau and kernel 6.12 i couldnt even get 1080p resolution
  • with nvidia and kernel 6.12 i could use 1080p but the performance was almost unusable, laggy cursor, disabled gnome animations, etc.
  • with nouveau and kernel 5.4 i got 1080p and a good performance, not laggy cursor and gnome enabled animations.

So it made sense to think older kernel was more performant for older gpus.

Hm, these things seem very unlikely to be caused by just kernel differences. Have you confirmed that that is the only variable with glxgears and glxinfo?

I dont know how to interpret the output of glxinfo, but the glxgears indeed “run better” with nvidia and default kernel, because it shows 2100+ fps and didnt freeze the computer, while with other configurations of nouveau and kernels it shows 60+ fps and froze the computer.

but the performance on gnome on nvidia and default kernel is clearly worse, outside the glxgears, i dont understand.

there is even a ghost monitor (i just use one 1080p monitor connected to the gpu).

That sounds a lot like gnome is just falling back to software rendering. Is there anything useful in your logs?