From d78549fef3f94624b3f431d761bc680e410ee927 Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Sat, 19 May 2018 21:37:45 +0200 Subject: [PATCH] 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 --- README.md | 18 ++++++++++++++---- default.nix | 5 +++-- nvidiaInstall.py | 13 +++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) create mode 100755 nvidiaInstall.py diff --git a/README.md b/README.md index 5ac4629..1da5284 100644 --- 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 index 5b650a4..4b6fc1a 100644 --- 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 new file mode 100755 index 0000000..d44f9e4 --- /dev/null +++ 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])