Building your own Nvidia packages

drivers
nvidia

#1

So you want to try out a newer version of the Nvidia driver, but want to install a package instead of running the Nvidia bundle?

Don’t want to wait for the Manjaro devs to update the driver, or want to try out a beta driver instead?

Don’t mind the extra maintenance of building your own driver modules?

Are you going to remember to do this each and every time you install a new kernel version?


Update: PKGBUILDs for “most recent” driver are available here:

Outline instructions:

git clone https://github.com/jonathonf/manjaro-nvidia.git
cd manjaro-nvidia/nvidia-utils
makepkg -Csrc
sudo pacman -Udd *pkg*xz
cd ../nvidia-414
makepkg -Csric

In-depth instructions for creating/editing your own PKGBUILDs

Warning: These steps are entirely unsupported and followed at your own risk. By following this guide you’re admitting you’re someone who is comfortable with fixing your own system.

OK? Then read on…


Nvidia drivers and tooling are split over a number of packages. The key PKGBUILDs are in -extra, e.g.:

and if you run Steam or 32-bit applications you’ll want:

Editing these PKGBUILD files will allow you build your own kernel modules that follow the Manjaro tooling, meaning you shouldn’t end up breaking your system.

Step 1

Prepare a Live CD/USB so you can fix your system or switch the drivers back to the repo versions.

Step 2

Download all the files from the nvidia-utils, (lib32-nvidia-utils,) and linux*-extramodules/nvidia directories on GitHub. Obviously, pick the extramodules that match your running kernel. If you have more then one kernel installed you’ll need to build multiple modules.

You’ll want to put these in separate directories, e.g. nvidia-utils, linux412-nvidia, etc.

Step 3

Edit the PKGBUILD files and change the pkgver variable to match the upstream driver version. Change the pkgrel to 0 so any official package update will be installed in preference.

TIP: add a suffix that matches your kernel version so you know whether you built for the current version, e.g. for 4.12.8, use pkgrel=0.8.

Step 4

Download the necessary files and update the checksums for the PKGBUILD files. In each directory, run:

updpkgsums

Step 5 part 1

Try building the nvidia-util PKGBUILD (makepkg -srcC). If you get errors, resolve them; for example, files might have moved or been renamed.

Check in the src subdirectory for the source files if e.g. files cannot be found. You may need to delete the pkg and src directories manually before each build attempt.

Here’s an edited PKGBUILD for 384.59:

# Contributor: Thomas Baechler <thomas@archlinux.org>
# Maintainer: Philip Müller <philm[at]manjaro[dog]org>

pkgbase=nvidia-utils
pkgname=('nvidia-utils' 'opencl-nvidia' 'mhwd-nvidia')
pkgver=384.59
pkgrel=0
epoch=1
arch=('i686' 'x86_64')
url="http://www.nvidia.com/"
license=('custom')
options=('!strip')
source=('mhwd-nvidia' 'nvidia-drm-outputclass.conf')
durl="http://us.download.nvidia.com/XFree86/Linux-x86"
#durl="http://developer.download.nvidia.com/assets/opengl/369.00"
source_i686=("${durl}/${pkgver}/NVIDIA-Linux-x86-${pkgver}.run")
#source_x86_64=("${durl}_64/${pkgver}/NVIDIA-Linux-x86_64-${pkgver}.run")
source_x86_64=("${durl}_64/${pkgver}/NVIDIA-Linux-x86_64-${pkgver}-no-compat32.run")
sha256sums=('11176f1c070bbdbfaa01a3743ec065fe71ff867b9f72f1dce0de0339b5873bb5'
            '37e2e35fcfc536a47212d57420ee3d8502b541a18027367104052aca63e63266')
sha256sums_i686=('0c17658a4f874df43c02b521cd0a1357dfe2ea0b553be6b47ebae2e45323916c')
sha256sums_x86_64=('2d03e687b6b77d072de057349fceb0b7b19a4387d610ea22928ce99d2945d165')

[[ "$CARCH" = "i686" ]] && _pkg="NVIDIA-Linux-x86-${pkgver}"
#[[ "$CARCH" = "x86_64" ]] && _pkg="NVIDIA-Linux-x86_64-${pkgver}"
[[ "$CARCH" = "x86_64" ]] && _pkg="NVIDIA-Linux-x86_64-${pkgver}-no-compat32"

create_links() {
    # create soname links
    for _lib in $(find "${pkgdir}" -name '*.so*' | grep -v 'xorg/'); do
        _soname=$(dirname "${_lib}")/$(readelf -d "${_lib}" | grep -Po 'SONAME.*: \[\K[^]]*' || true)
        _base=$(echo ${_soname} | sed -r 's/(.*).so.*/\1.so/')
        [[ -e "${_soname}" ]] || ln -s $(basename "${_lib}") "${_soname}"
        [[ -e "${_base}" ]] || ln -s $(basename "${_soname}") "${_base}"
    done
}

prepare() {
    sh "${_pkg}.run" --extract-only

    cd "${_pkg}"
    bsdtar -xf nvidia-persistenced-init.tar.bz2
}

package_opencl-nvidia() {
    pkgdesc="OpenCL implemention for NVIDIA"
    depends=('zlib')
    optdepends=('opencl-headers: headers necessary for OpenCL development')
    provides=('opencl-nvidia' 'opencl-driver')
    cd "${_pkg}"

    # OpenCL
    install -D -m644 nvidia.icd "${pkgdir}/etc/OpenCL/vendors/nvidia.icd"
    install -D -m755 "libnvidia-compiler.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-compiler.so.${pkgver}"
    install -D -m755 "libnvidia-opencl.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-opencl.so.${pkgver}"

    create_links

    mkdir -p "${pkgdir}/usr/share/licenses"
    ln -s nvidia "${pkgdir}/usr/share/licenses/opencl-nvidia"
}


package_mhwd-nvidia() {
    pkgdesc="MHWD module-ids for nvidia $pkgver"
    arch=('any')

    install -d -m755 "${pkgdir}/var/lib/mhwd/ids/pci/"

    # Generate mhwd database
    sh -e ${srcdir}/mhwd-nvidia \
    ${srcdir}/${_pkg}/README.txt \
    ${srcdir}/${_pkg}/kernel/nvidia/nv-kernel.o_binary \
    > ${pkgdir}/var/lib/mhwd/ids/pci/nvidia.ids
}


package_nvidia-utils() {
    pkgdesc="NVIDIA drivers utilities"
    depends=('xorg-server' 'libglvnd' 'mhwd')
    optdepends=('gtk2: nvidia-settings'
                'xorg-server-devel: nvidia-xconfig'
                'opencl-nvidia: OpenCL support')
    provides=('nvidia-libgl')
    conflicts=('nvidia-libgl')
    replaces=('nvidia-libgl')
    install="${pkgname}.install"

    cd "${_pkg}"

    # X driver
    install -D -m755 nvidia_drv.so "${pkgdir}/usr/lib/xorg/modules/drivers/nvidia_drv.so"

    # GLX extension module for X
    install -D -m755 "libglx.so.${pkgver}" "${pkgdir}/usr/lib/nvidia/xorg/libglx.so.${pkgver}"
    ln -s "libglx.so.${pkgver}" "${pkgdir}/usr/lib/nvidia/xorg/libglx.so.1"	# X doesn't find glx otherwise
    ln -s "libglx.so.${pkgver}" "${pkgdir}/usr/lib/nvidia/xorg/libglx.so"	# X doesn't find glx otherwise
    install -D -m755 "libGLX_nvidia.so.${pkgver}" "${pkgdir}/usr/lib/libGLX_nvidia.so.${pkgver}"
    #ln -s "libGLX_nvidia.so.${pkgver}" "${pkgdir}/usr/lib/libGLX_indirect.so.0"

    # Wayland
    install -D -m755 "libnvidia-egl-wayland.so.1.0.1" "${pkgdir}/usr/lib/libnvidia-egl-wayland.so.${pkgver}"
    ln -s "libnvidia-egl-wayland.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-egl-wayland.so.0"

    # OpenGL library
    install -D -m755 "libGL.so.1.0.0" "${pkgdir}/usr/lib/nvidia/libGL.so.1.0.0"
    install -D -m755 "libEGL.so.1" "${pkgdir}/usr/lib/nvidia/libEGL.so.1.0.0"
    install -D -m755 "libEGL_nvidia.so.${pkgver}" "${pkgdir}/usr/lib/libEGL_nvidia.so.${pkgver}"
    install -D -m755 "libGLESv1_CM_nvidia.so.${pkgver}" "${pkgdir}/usr/lib/libGLESv1_CM_nvidia.so.${pkgver}"
    install -D -m755 "libGLESv2_nvidia.so.${pkgver}" "${pkgdir}/usr/lib/libGLESv2_nvidia.so.${pkgver}"
    install -D -m644 "10_nvidia.json" "${pkgdir}/usr/share/glvnd/egl_vendor.d/10_nvidia.json"

    # OpenGL core library
    install -D -m755 "libnvidia-glcore.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-glcore.so.${pkgver}"
    install -D -m755 "libnvidia-eglcore.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-eglcore.so.${pkgver}"
    install -D -m755 "libnvidia-glsi.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-glsi.so.${pkgver}"

    # misc
    install -D -m755 "libnvidia-ifr.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-ifr.so.${pkgver}"
    install -D -m755 "libnvidia-fbc.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-fbc.so.${pkgver}"
    install -D -m755 "libnvidia-encode.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-encode.so.${pkgver}"
    install -D -m755 "libnvidia-cfg.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-cfg.so.${pkgver}"
    install -D -m755 "libnvidia-ml.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-ml.so.${pkgver}"

    # Vulkan ICD
    install -D -m644 "nvidia_icd.json.template" "${pkgdir}/usr/share/vulkan/icd.d/nvidia_icd.json"

    # VDPAU
    install -D -m755 "libvdpau_nvidia.so.${pkgver}" "${pkgdir}/usr/lib/vdpau/libvdpau_nvidia.so.${pkgver}"

    # nvidia-tls library
    install -D -m755 "libnvidia-tls.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-tls.so.${pkgver}"
    install -D -m755 "tls/libnvidia-tls.so.${pkgver}" "${pkgdir}/usr/lib/tls/libnvidia-tls.so.${pkgver}"

    # CUDA
    install -D -m755 "libcuda.so.${pkgver}" "${pkgdir}/usr/lib/libcuda.so.${pkgver}"
    install -D -m755 "libnvcuvid.so.${pkgver}" "${pkgdir}/usr/lib/libnvcuvid.so.${pkgver}"

    # PTX JIT Compiler (Parallel Thread Execution (PTX) is a pseudo-assembly language for CUDA)
    install -D -m755 "libnvidia-ptxjitcompiler.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-ptxjitcompiler.so.${pkgver}"

    # Fat (multiarchitecture) binary loader
    install -D -m755 "libnvidia-fatbinaryloader.so.${pkgver}" "${pkgdir}/usr/lib/libnvidia-fatbinaryloader.so.${pkgver}"

    # DEBUG
    install -D -m755 nvidia-debugdump "${pkgdir}/usr/bin/nvidia-debugdump"

    # nvidia-xconfig
    install -D -m755 nvidia-xconfig "${pkgdir}/usr/bin/nvidia-xconfig"
    install -D -m644 nvidia-xconfig.1.gz "${pkgdir}/usr/share/man/man1/nvidia-xconfig.1.gz"

    # nvidia-settings
    install -D -m755 nvidia-settings "${pkgdir}/usr/bin/nvidia-settings"
    install -D -m644 nvidia-settings.1.gz "${pkgdir}/usr/share/man/man1/nvidia-settings.1.gz"
    install -D -m644 nvidia-settings.desktop "${pkgdir}/usr/share/applications/nvidia-settings.desktop"
    install -D -m644 nvidia-settings.png "${pkgdir}/usr/share/pixmaps/nvidia-settings.png"
    install -D -m755 "libnvidia-gtk2.so.$pkgver" "$pkgdir/usr/lib/libnvidia-gtk2.so.$pkgver"
    install -D -m755 "libnvidia-gtk3.so.$pkgver" "$pkgdir/usr/lib/libnvidia-gtk3.so.$pkgver"
    sed -e 's:__UTILS_PATH__:/usr/bin:' -e 's:__PIXMAP_PATH__:/usr/share/pixmaps:' -i "${pkgdir}/usr/share/applications/nvidia-settings.desktop"

    # nvidia-bug-report
    install -D -m755 nvidia-bug-report.sh "${pkgdir}/usr/bin/nvidia-bug-report.sh"

    # nvidia-smi
    install -D -m755 nvidia-smi "${pkgdir}/usr/bin/nvidia-smi"
    install -D -m644 nvidia-smi.1.gz "${pkgdir}/usr/share/man/man1/nvidia-smi.1.gz"

    # nvidia-cuda-mps
    install -D -m755 nvidia-cuda-mps-server "${pkgdir}/usr/bin/nvidia-cuda-mps-server"
    install -D -m755 nvidia-cuda-mps-control "${pkgdir}/usr/bin/nvidia-cuda-mps-control"
    install -D -m644 nvidia-cuda-mps-control.1.gz "${pkgdir}/usr/share/man/man1/nvidia-cuda-mps-control.1.gz"

    # nvidia-modprobe
    # This should be removed if nvidia fixed their uvm module!
    install -D -m4755 nvidia-modprobe "${pkgdir}/usr/bin/nvidia-modprobe"
    install -D -m644 nvidia-modprobe.1.gz "${pkgdir}/usr/share/man/man1/nvidia-modprobe.1.gz"

    # nvidia-persistenced
    install -D -m755 nvidia-persistenced "${pkgdir}/usr/bin/nvidia-persistenced"
    install -D -m644 nvidia-persistenced.1.gz "${pkgdir}/usr/share/man/man1/nvidia-persistenced.1.gz"
    install -D -m644 nvidia-persistenced-init/systemd/nvidia-persistenced.service.template "${pkgdir}/usr/lib/systemd/system/nvidia-persistenced.service"
    sed -i 's/__USER__/nvidia-persistenced/' "${pkgdir}/usr/lib/systemd/system/nvidia-persistenced.service"

    # application profiles
    install -D -m644 nvidia-application-profiles-${pkgver}-rc "${pkgdir}/usr/share/nvidia/nvidia-application-profiles-${pkgver}-rc"
    install -D -m644 nvidia-application-profiles-${pkgver}-key-documentation "${pkgdir}/usr/share/nvidia/nvidia-application-profiles-${pkgver}-key-documentation"

    install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/nvidia/LICENSE"
    ln -s nvidia "${pkgdir}/usr/share/licenses/nvidia-utils"
    install -D -m644 README.txt "${pkgdir}/usr/share/doc/nvidia/README"
    install -D -m644 NVIDIA_Changelog "${pkgdir}/usr/share/doc/nvidia/NVIDIA_Changelog"
    cp -r html "${pkgdir}/usr/share/doc/nvidia/"
    ln -s nvidia "${pkgdir}/usr/share/doc/nvidia-utils"

    # distro specific files must be installed in /usr/share/X11/xorg.conf.d
    install -m755 -d "${pkgdir}/usr/share/X11/xorg.conf.d"
    install -m644 "${srcdir}/nvidia-drm-outputclass.conf" "${pkgdir}/usr/share/X11/xorg.conf.d/"

    create_links
}

Step 5 part 2

Install the new packages, e.g.

sudo pacman -Udd nvidia-utils-1:384.59-0-x86_64.pkg.tar.xz mhwd-nvidia-1:384.59-0-any.pkg.tar.xz

-dd is necessary as this will break older installed extramodules. DO NOT REBOOT HERE.

Step 5 part 3

Repeat part 1 above for lib32-nvidia-utils should you need it:

  • Edit the PKGBUILD file in the same way; any changes to file locations will be the same as for nvidia-utils
  • Build and install with makepkg -Csric

The packages do not have a version requirement so can be built and installed in one go.

Step 6

Build and install the extramodule (makepkg -sric). This shouldn’t need any intervention.

Step 7

Build the module for any other kernels you have installed.

Step 8

Cross your fingers and reboot.

Step 9+

Rebuild the extramodules every time you install or update your kernel(s). This ensures they will work correctly with any changes in the kernel.

Step Z

Want to switch back to the repo versions? Easy:

sudo pacman -Syuu

will downgrade your packages back to those in the repos.


Further reading:


Tutorial - How to Install Nvidia drivers from the Nvidia website
How about now ? Will manjaro update its old and buggy nvidia driver?
Nvidia drivers update
[Unstable Update] 2017-07-29 - Kernels, Virtualbox, spl/zfs, Cinnamon, Pamac
Request: can we have a faster push for nvidia-390 to the stable branch?
Cuda version issue.. I updated, it broke all cuda functionality because everything wants 9.0, not 9.1
How to downgrade NVIDIA drivers?
Why install packages instead of running installer script?
Why install packages instead of running installer script?
Is it safe to postpone nvidia driver updates?
[Testing Update] 2018-01-18 - Kernels, Systemd, Pamac, KDE FW, Haskell, Python
Bumblebee - upgrading Nvidia drivers from stable version 384 to beta version 390
Screen Tearing on Gnome running Bumblebee
Installation problem of nvidia driver
Installation problem of nvidia driver
Cuda 9.1. not compatible with nvidia 384
OpenGL 4.6 NVIDIA?
#2

Let me just add that it’s highly recommended to rebuild the nvidia module with each kernel upgrade.

For the rest: perfect tutorial! I followed a very similar procedure last year and it worked well.


#3

Would be nice to here from $tester, which card and kernel works…!

@jonathon
Why can I edit your post?
Is this intentionally?


#4

That’s the fourth line of the post. :wink:

It’s a wiki post. It means others can update it if needed and I’m not around/busy/hiding.


#5

Oh dear, I read through this too quickly :slight_smile:


#6

Let me go and add a

Step 9

Rebuild the extramodules every time you install or update your kernel(s).


#7

You might wan’t to change the makepkg command in Step 4 part 1, since the -i option is not working and it is not always a good idea to install every packages makepkg build. But on Step 5 the -i option is maybe handy.

Also I would also suggest the -c option of makepkg. It cleans the build folder after a successful build.


#8

Removing -i makes sense - you’re right, it won’t work when dependencies need to be ignored.

I also like -c now - I thought it cleaned after any build which isn’t useful for resolving build issues, but it only cleans after successful builds, which is fine.

-c, --clean
           Clean up leftover work files and directories after a successful build.

#9

I like this option, since it only removes the pkg and src folder if the build was successful. Downloaded files and the pkg.tar.xz stays obviously.


#10

I would also add -C for even more cleaning. But I guess most people build in tmpfs, so most of the stuff is cleared at shutdown.


#11
-C, --cleanbuild
           Remove the $srcdir before building the package.

makes sense to put that in Step 4 pt 1; building will fail if $srcdir is present.


#12

4 posts were split to a new topic: Why install packages instead of running installer script?


Why install packages instead of running installer script?
#13

The -C option don’t mean more cleaning. It will only remove a src Folder, if there is one, before the build starts. After the packages are created, the src and pkg folder stays.
The -c option cleans after a build, so you don’t need the -C option, except the build fails.


#14

Thanks for this.

Imho it would also be very helpfull if somebody wants to switch back to the original package.
So would you please add an extra point how to switch back.
Thanks in advance.


#15

For switching back, just install the packages with pacman -S.

For example, you use Linux 4.12 and did run Step 4 part 2 as described, do

pacman -S nvidia-utils mhwd-nvidia linux412-nvidia

If there is a question about downgrade, answer with yes.


#16

Yes, you’re right. The -C option has become a habit for me because I often had failed builds while experimenting…


#17

On thing that maybe should also included in the tutorial is building lib32-nvidia-utils or at least mentioned. If you run x86_64 and want play games with Steam, lib32-nvidia-utils is needed.
Since lib32-nvidia-utils doesn’t depend on nvidia-utils, there is no notification/errror that lib32-nvidia-utils is to old. Steam don’t start if the 32bit and 64bit versions are different.