Error installing NVIDIA drivers on Ubuntu

Hey! I can’t seem to get the NVIDIA driver on my Ubuntu machine to work. This happened after installing the 6.0 kernel, through Ubuntu Mainline. I’m back at 5.19.11, but can’t install the nvidia driver. I’ve tried many proposed things, but always with the same result. This is the output I get running sudo apt install nvidia-driver-515:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
nvidia-driver-515 is already the newest version (515.76-0ubuntu0.22.04.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up nvidia-dkms-515 (515.76-0ubuntu0.22.04.1) ...
update-initramfs: deferring update (trigger activated)
INFO:Enable nvidia
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/lenovo_thinkpad
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/put_your_quirks_here
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/dell_latitude
Removing old nvidia-515.76 DKMS files...
Deleting module nvidia-515.76 completely from the DKMS tree.
Loading new nvidia-515.76 DKMS files...
Building for 5.19.11-051911-generic
Building for architecture x86_64
Building initial module for 5.19.11-051911-generic
ERROR (dkms apport): kernel package linux-headers-5.19.11-051911-generic is not 
supported
Error! Bad return status for module build on kernel: 5.19.11-051911-generic (x86
_64)
Consult /var/lib/dkms/nvidia/515.76/build/make.log for more information.
dpkg: error processing package nvidia-dkms-515 (--configure):
 installed nvidia-dkms-515 package post-installation script subprocess returned 
error exit status 10
dpkg: dependency problems prevent configuration of nvidia-driver-515:
 nvidia-driver-515 depends on nvidia-dkms-515 (<= 515.76-1); however:
  Package nvidia-dkms-515 is not configured yet.
 nvidia-driver-515 depends on nvidia-dkms-515 (>= 515.76); however:
  Package nvidia-dkms-515 is not configured yet.

dpkg: error processing package nvidia-driver-515 (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup erro
r from a previous failure.
                          Processing triggers for initramfs-tools (0.140ubuntu13
) ...
update-initramfs: Generating /boot/initrd.img-5.19.11-051911-generic
Errors were encountered while processing:
 nvidia-dkms-515
 nvidia-driver-515
E: Sub-process /usr/bin/dpkg returned an error code (1)

OS: Ubuntu 22.04.1 LTS
Laptop: Lenovo Legion S7 15ACH6
GPU: Geforce RTX 3060
CPU: AMD Ryzen 7 5800h

Thanks for any help!

Please attach it.

Here it is
make.log (36.0 KB)

The kernel was compiled with gcc 12.2 so the headers are incompatible. Please use the liquorix ppa get get a compatible kernel.

I installed nvidia 515, but it gave the same error (I think) for the 6.0 kernel and won’t work with that.
But, it is working with kernel 5.19, which seems to also be built with gcc 12.2 . The make.log says that the kernel was built with 12.1.0, but cat /proc/version says 12.2.0 so I don’t know why it would work with one but not the other for me if gcc being version 11 is important. nvidia 520 doesn’t seem to work with either.

Is there a place where I can find the 520 nvidia driver built with a current gcc version so it will work with an up to date kernel?

nvidia driver 515.76
$ cat /proc/version
Linux version 5.19.5-051905-generic (kernel@kathleen) (x86_64-linux-gnu-gcc (Ubuntu 12.2.0-1ubuntu1) 12.2.0, GNU ld (GNU Binutils for Ubuntu) 2.39) #202208291036 SMP PREEMPT_DYNAMIC Mon Aug 29 10:47:31 UTC 2022