How can I convert the Nvidia driver installer into a deb?

Every so often there's a beta version of the Nvidia driver that I want to try out. This has happened today: there's been a big performance issue with version 295.40 and I want to try the shiny new XRandR-enabled 302.07.

I'm more than able to download the installer, remove all the repo-installed driver files and install the new version but it's frankly a pain in the bottom to turn that around and go back to the repo version. It also means I have to re-install the driver manually each time there's a Kernel upgrade.

The other option we commonly give people is a PPA but in this case I'm being really impatient. It's going to be a few days before any PPA gets this but I need to try this today. I've already manually installed it on the media centre and I'm eyeing up my desktop now.

So how do I take an installer (eg: NVIDIA-Linux-x86-302.07.run) and convert that into a new nvidia-current/nvidia-current-updates package?

Another way of asking this might be: How do people package the Nvidia drivers?


Solution 1:

Unless there are structural differences i the new version it should be possible to re-use the current packaging:

NEWVERSION=302.13
DIR=nvidia-graphics-drivers-"$NEWVERSION".orig/
## Making a new tarball
mkdir $DIR
# Copy in new run files
cp NVIDIA*.run $DIR
tar --owner=root --group=src -caf nvidia-graphics-drivers_"$NEWVERSION".orig.tar.gz $DIR
rm -r $DIR

## Setting up the packaging source
apt-get source nvidia-graphics-drivers
cd nvidia-graphics-drivers*/
# Remove old run files and copy in new
rm NVIDIA*.run
cp ../NVIDIA*.run .
# This version number should ensure it gets replaced by official version...
dch -v $VERSION-1 "my release"; dch -l~mybuild "local build"; dch -r

## Installing build-dependencies
mk-build-deps
sudo dpkg -i nvidia-graphics-drivers-build-deps*.deb; apt-get install -f

## Building
debuild -us -uc

Something like that might work, there's quite a bit of mucking around, which I guess is why PPA packages don't get released instantly ;)

Solution 2:

As arand said, you can use the existing source packages assuming that it has not changed too much. The below commands will download a .run file, retrieve and adapt existing source files and finally package it.

Prepare for installation by installing some build dependencies:

sudo apt-get build-dep nvidia-graphics-drivers
sudo apt-get install execstack # needed but not included with build-deps

To prepare, set some variables that control the files being downloaded and create a new directory for it:

VER=310.19
mkdir nvidia-graphics-drivers-$VER; cd nvidia-graphics-drivers-$VER

Download the file named like NVIDIA-Linux-x86-310.19.run if you have not already. If you have a 64-bit machine, you should also download the 64-bit installer which is named like NVIDIA-Linux-x86_64-310.19-no-compat32.run:

wget ftp://download.nvidia.com/XFree86/Linux-x86/$VER/NVIDIA-Linux-x86-$VER.run
wget ftp://download.nvidia.com/XFree86/Linux-x86_64/$VER/NVIDIA-Linux-x86_64-$VER-no-compat32.run

Now retrieve the packaging files, "extract" it, change the version number and build the package without signing it:

apt-get source --diff-only nvidia-current
gunzip -c *.diff.gz | patch -p1
dch -v $VER-0~local "New upstream release."

Now, at the time of this writing, version 295.40-0ubuntu1.1 does not build 310.19 because the packaging has changed. It turns out that libXvMCNvidia.* files have been removed, so let's delete those lines including XvMCConfig:

sed -i '/XvMC/d' debian/{*.links*.in,*.install.in,rules}

Build the package:

dpkg-buildpackage -b -uc -us

If all went well, you should now be able to install the resulting deb file with:

sudo dpkg -i ../nvidia-current_$VER-*.deb; sudo apt-get install -f

(the sudo apt-get install -f command is optional if you have installed nvidia-current before, and do not run into dependency issues)