nvidia 387.26 for ubuntu 16.04 package broken?

When installing the nvidia-387 (387.26; package from http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/) I get this error:

Error! Bad return status for module build on kernel: 4.13.0-38-generic (x86_64)
Consult /var/lib/dkms/nvidia-387/387.26/build/make.log for more information.
the error in the log file:

./arch/x86/include/asm/processor.h:818:39: error: implicit declaration of function ‘task_stack_page’ [-Werror=implicit-function-declaration]

uname - Linux testvm-VirtualBox 4.13.0-38-generic #43~16.04.1-Ubuntu SMP Wed Mar 14 17:48:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
gcc - gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609

Also when I tried to install the package in a docker environment to see what’s going on, I got this output -

update-alternatives: using /usr/lib/nvidia-387/ld.so.conf to provide /etc/ld.so.conf.d/x86_64-linux-gnu_GL.conf (x86_64-linux-gnu_gl_conf) in auto mode
update-alternatives: warning: skip creation of /usr/share/grub-gfxpayload-lists/blacklist/10_proprietary-graphics-drivers because associated file /usr/share/nvidia-387/nvidia-387.grub-gfxpayload (of link group x86_64-linux-gnu_gl_conf) doesn’t exist
update-alternatives: error: error creating symbolic link ‘/usr/lib/nvidia/alternate-install-present.dpkg-tmp’: No such file or directory
dpkg: error processing package nvidia-387 (–configure):
subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of libcuda1-387:
libcuda1-387 depends on nvidia-387 (>= 387.26); however:
Package nvidia-387 is not configured yet.

dpkg: error processing package libcuda1-387 (–configure):
dependency problems - leaving unconfigured

This is caused by line 144 in the package’s postinst script (the last line of the update-alternatives command). Seems like the script incorrectly assumes that the folder /usr/lib/nvidia exists (it might not) and the package never actually creates this directory in neither installation scripts nor is it present in the data package.

Anything? Could I have an actual nvidia employee acknowledge something or are they too busy figuring out how to increase AMDs market share to care?

Package nvidia-396 has the same problem.

Workaround:

sudo mkdir /usr/lib/nvidia
sudo apt-get install nvidia-396

While it might help with the weird stuff they have in their postinst script, installing a newer driver isn’t really feasable fix for the kernel module problem because the new drivers induce instability (flickering, delays) in gstreamer (with nvenc) based applications which I rely on.

Best fix I can think of right now is to stop relying on nvidia’s hardware and buy AMD instead.

Oh yeah, I wasn’t suggesting this as a fix to the original problem. I was just pointing out that the problem is still present in their newer drivers, and offering a quick workaround to anyone else caught out by it.

DrMcCleod: The workaround with sudo mkdir /usr/lib/nvidia worked for me (nvidia-390, nvidia-396 on Ubuntu on EC2). Thanks!

Yes. This method also worked for me. Thanks!

linlf@dacent:~$ sudo mkdir /usr/lib/nvidia
linlf@dacent:~$ sudo apt-get install nvidia-384
Reading package lists... Done
Building dependency tree       
Reading state information... Done
nvidia-384 is already the newest version (384.145-0ubuntu1).
The following packages were automatically installed and are no longer required:
  libnvidia-container-tools libnvidia-container1 linux-headers-4.4.0-116 linux-headers-4.4.0-116-generic linux-headers-4.4.0-130 linux-headers-4.4.0-130-generic
  linux-headers-4.4.0-134 linux-headers-4.4.0-134-generic linux-image-4.4.0-116-generic linux-image-4.4.0-130-generic linux-image-4.4.0-134-generic
  linux-image-extra-4.4.0-116-generic linux-image-extra-4.4.0-130-generic linux-image-extra-4.4.0-134-generic linux-tools-4.4.0-130 linux-tools-4.4.0-130-generic
  linux-tools-4.4.0-134 linux-tools-4.4.0-134-generic nvidia-container-runtime nvidia-container-runtime-hook
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 1 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-384 (384.145-0ubuntu1) ...
update-alternatives: using /usr/lib/nvidia-384/ld.so.conf to provide /etc/ld.so.conf.d/x86_64-linux-gnu_GL.conf (x86_64-linux-gnu_gl_conf) in auto mode
update-alternatives: warning: skip creation of /usr/share/grub-gfxpayload-lists/blacklist/10_proprietary-graphics-drivers because associated file /usr/share/nvidia-38
4/nvidia-384.grub-gfxpayload (of link group x86_64-linux-gnu_gl_conf) doesn't existupdate-alternatives: using /usr/lib/nvidia-384/ld.so.conf to provide /etc/ld.so.conf.d/x86_64-linux-gnu_EGL.conf (x86_64-linux-gnu_egl_conf) in auto mode
update-alternatives: using /usr/lib/nvidia-384/alt_ld.so.conf to provide /etc/ld.so.conf.d/i386-linux-gnu_GL.conf (i386-linux-gnu_gl_conf) in auto mode
update-alternatives: using /usr/lib/nvidia-384/alt_ld.so.conf to provide /etc/ld.so.conf.d/i386-linux-gnu_EGL.conf (i386-linux-gnu_egl_conf) in auto mode
update-alternatives: using /usr/share/nvidia-384/glamor.conf to provide /usr/share/X11/xorg.conf.d/glamoregl.conf (glamor_conf) in auto mode
update-initramfs: deferring update (trigger activated)

A modprobe blacklist file has been created at /etc/modprobe.d to prevent Nouveau from loading. This can be reverted by deleting /etc/modprobe.d/nvidia-graphics-driver
s.conf.A new initrd image has also been created. To revert, please replace /boot/initrd-4.4.0-138-generic with /boot/initrd-$(uname -r)-backup.

*****************************************************************************
*** Reboot your computer and verify that the NVIDIA graphics driver can   ***
*** be loaded.                                                            ***
*****************************************************************************

Adding system user `nvidia-persistenced' (UID 113) ...
Adding new group `nvidia-persistenced' (GID 119) ...
Adding new user `nvidia-persistenced' (UID 113) with group `nvidia-persistenced' ...
Not creating home directory `/'.
Loading new nvidia-384-384.145 DKMS files...
First Installation: checking all kernels...
Building only for 4.4.0-138-generic
Building for architecture x86_64
Building initial module for 4.4.0-138-generic
Done.

nvidia_384:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.4.0-138-generic/updates/dkms/

nvidia_384_modeset.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.4.0-138-generic/updates/dkms/

nvidia_384_drm.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.4.0-138-generic/updates/dkms/

nvidia_384_uvm.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/4.4.0-138-generic/updates/dkms/

depmod....

DKMS: install completed.
Setting up libcuda1-384 (384.145-0ubuntu1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for initramfs-tools (0.122ubuntu8.11) ...
update-initramfs: Generating /boot/initrd.img-4.4.0-138-generic
W: Possible missing firmware /lib/firmware/ast_dp501_fw.bin for module ast
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.