commit d78549fef3f94624b3f431d761bc680e410ee927
parent 624ea697ac728133d6ec097bf5028c0f2b53dbe0
Author: Guillaume Bouchard <guillaum.bouchard@gmail.com>
Date: Sat, 19 May 2018 21:37:45 +0200
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
Diffstat:
3 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
@@ -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
```
diff --git a/default.nix b/default.nix
@@ -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;
});
diff --git a/nvidiaInstall.py b/nvidiaInstall.py
@@ -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])