Create a wrapper for nvidia install

Hash of nvidia driver is not known because it depends on the driver version
(argument `nvidiaVersion`). However, since nix 2.0 and when using `useSandbox`,
`sha256 = null` is not allowed anymore.

The new wrapper script, `nvidiaInstall.py` uses `nix-prefetch-url` to compute
the hash and call `nix`.

This is a fix for #9
This commit is contained in:
Guillaume Bouchard 2018-05-19 21:37:45 +02:00
parent 624ea697ac
commit d78549fef3
3 changed files with 30 additions and 6 deletions

View File

@ -10,7 +10,9 @@ git clone https://github.com/guibou/nixGL
cd nixGL
# build and install the wrapper
nix-build -A nixGLNvidia --argstr nvidiaVersion 390.25
./nvidiaInstall.py 390.25 nixGLNvidia
# install the wrapper
nix-env -i ./result
# use it with any OpenGL application
@ -62,6 +64,8 @@ OpenGL core profile version string: 4.5.0 NVIDIA 390.25
## Build
### For mesa (intel, amd, nouveau, ...)
For mesa (intel, amd, nouveau) GL, the package is historically called `nixGLIntel`:
```
@ -74,10 +78,14 @@ For Intel Vulkan:
nix-build -A nixVulkanIntel
```
### For nvidia
Due to some restriction on `nix` 2.0, the `nix-build` must be called with a wrapper script.
For NVIDIA GL alone:
```
nix-build -A nixGLNvidia --argstr nvidiaVersion 390.25
./nvidiaInstall.py 390.25 nixGLNvidia
```
For NVIDIA Vulkan alone:
@ -85,7 +93,7 @@ For NVIDIA Vulkan alone:
Note that the NVIDIA GL and Vulkan wrappers are identical aside from the name
```
nix-build -A nixVulkanNvidia --argstr nvidiaVersion 390.25
./nvidiaInstall.py 390.25 nixVulkanNvidia
```
(replace `390.25` with the host driver version gathered earlier.)
@ -93,13 +101,15 @@ nix-build -A nixVulkanNvidia --argstr nvidiaVersion 390.25
For Nvidia with bumblebee:
```
nix-build -A nixGLNvidiaBumblebee --argstr nvidiaVersion 390.25
./nvidiaInstall.py 390.25 nixGLNvidiaBumblebee
```
(replace `390.25` with the host driver version gathered earlier.)
## Install
The previous commands only build the wrapper, now stored inside `./result`, you need to install it:
```
nix-env -i ./result
```

View File

@ -1,5 +1,6 @@
{ system ? builtins.currentSystem,
nvidiaVersion ? null
nvidiaVersion ? null,
nvidiaHash ? null
}:
let
@ -16,7 +17,7 @@ rec {
name = "nvidia-${nvidiaVersion}";
src = fetchurl {
url = "http://download.nvidia.com/XFree86/Linux-x86_64/${nvidiaVersion}/NVIDIA-Linux-x86_64-${nvidiaVersion}.run";
sha256 = null;
sha256 = nvidiaHash;
};
useGLVND = 0;
});

13
nvidiaInstall.py Executable file
View File

@ -0,0 +1,13 @@
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3
import sys
import subprocess
nvidiaVersion = sys.argv[1]
tool = sys.argv[2]
nvidiaUrl = f"http://download.nvidia.com/XFree86/Linux-x86_64/{nvidiaVersion}/NVIDIA-Linux-x86_64-{nvidiaVersion}.run"
nvidiaHash = subprocess.check_output(["nix-prefetch-url", nvidiaUrl]).strip()
subprocess.check_call(["nix-build", "-A", tool, "--argstr", "nvidiaVersion", nvidiaVersion, "--argstr", "nvidiaHash", nvidiaHash])