allow to pass a nvidiaVersionFile

This allows to better control which driver is being loaded.
This commit is contained in:
zimbatm 2020-04-28 11:35:04 +02:00
parent 7f934a88ce
commit 7aa1cce7c6
No known key found for this signature in database
GPG Key ID: 71BAF6D40C1D63D7
3 changed files with 75 additions and 41 deletions

14
all.nix
View File

@ -1,4 +1,16 @@
import ./default.nix { let
pkgs = import <nixpkgs> { config = { allowUnfree = true; }; };
in
{
pure = pkgs.recurseIntoAttrs (pkgs.callPackage ./nixGL.nix {
nvidiaVersion = "440.82"; nvidiaVersion = "440.82";
nvidiaHash = "edd415acf2f75a659e0f3b4f27c1fab770cf21614e84a18152d94f0d004a758e"; nvidiaHash = "edd415acf2f75a659e0f3b4f27c1fab770cf21614e84a18152d94f0d004a758e";
});
versionFile = pkgs.recurseIntoAttrs (pkgs.callPackage ./nixGL.nix {
nvidiaVersionFile = pkgs.writeText "nvidia-version-440.82" ''
NVRM version: NVIDIA UNIX x86_64 Kernel Module 440.82 Wed Apr 1 20:04:33 UTC 2020
GCC version: gcc version 9.3.0 (Arch Linux 9.3.0-1)
'';
});
} }

View File

@ -4,6 +4,11 @@
# Hash of the Nvidia driver .run file. null is fine, but fixing a value here # Hash of the Nvidia driver .run file. null is fine, but fixing a value here
# will be more reproducible and more efficient. # will be more reproducible and more efficient.
nvidiaHash ? null, nvidiaHash ? null,
# Alternatively, you can pass a path that points to a nvidia version file
# and let nixGL extract the version from it. That file must be a copy of
# /proc/driver/nvidia/version. Nix doesn't like zero-sized files (see
# https://github.com/NixOS/nix/issues/3539 ).
nvidiaVersionFile ? null,
# Enable 32 bits driver # Enable 32 bits driver
# This is one by default, you can switch it to off if you want to reduce a # This is one by default, you can switch it to off if you want to reduce a
# bit the size of nixGL closure. # bit the size of nixGL closure.
@ -15,5 +20,10 @@
} }
}: }:
pkgs.callPackage ./nixGL.nix { pkgs.callPackage ./nixGL.nix {
inherit nvidiaVersion nvidiaHash enable32bits; inherit
nvidiaVersion
nvidiaVersionFile
nvidiaHash
enable32bits
;
} }

View File

@ -4,6 +4,11 @@
# Hash of the Nvidia driver .run file. null is fine, but fixing a value here # Hash of the Nvidia driver .run file. null is fine, but fixing a value here
# will be more reproducible and more efficient. # will be more reproducible and more efficient.
nvidiaHash ? null, nvidiaHash ? null,
# Alternatively, you can pass a path that points to a nvidia version file
# and let nixGL extract the version from it. That file must be a copy of
# /proc/driver/nvidia/version. Nix doesn't like zero-sized files (see
# https://github.com/NixOS/nix/issues/3539 ).
nvidiaVersionFile ? null,
# Enable 32 bits driver # Enable 32 bits driver
# This is one by default, you can switch it to off if you want to reduce a # This is one by default, you can switch it to off if you want to reduce a
# bit the size of nixGL closure. # bit the size of nixGL closure.
@ -14,27 +19,35 @@
}: }:
let let
# The nvidia version. Either fixed by the `nvidiaVersion` argument, or _nvidiaVersionFile =
# auto-detected. if nvidiaVersionFile != null then
_nvidiaVersion = if nvidiaVersion != null nvidiaVersionFile
then nvidiaVersion
else else
# This is the auto-detection mecanism. This is ugly. # HACK: Get the version from /proc. It turns out that /proc is mounted
# We read /proc/driver/nvidia/version which is set by the Nvidia driver kernel module. # inside of the build sandbox and varies from machine to machine.
# This fails if the nvidia driver kernel module is not loaded. #
# I'd like to just read the file using `${/proc/driver/nvidia/version}` and # builtins.readFile is not able to read /proc files. See
# then let nix invalidate the derivation if the content of this file # https://github.com/NixOS/nix/issues/3539.
# changes, but that's not possible, see runCommand "impure-nvidia-version-file" {
# https://github.com/NixOS/nix/issues/3539 # To avoid sharing the build result over time or between machine,
# But /proc is readable at build time! So runCommand works fine. # Add an impure parameter to force the rebuild on each access.
import (runCommand "auto-detect-nvidia" {
time = builtins.currentTime; time = builtins.currentTime;
} }
'' "cp /proc/driver/nvidia/version $out";
# Written this way so if the version file does not exists, the script crashs
VERSION="$(${pcre}/bin/pcregrep -o1 'Module +([0-9]+\.[0-9]+)' /proc/driver/nvidia/version)" # The nvidia version. Either fixed by the `nvidiaVersion` argument, or
echo "\"$VERSION\"" > $out # auto-detected. Auto-detection is impure.
''); _nvidiaVersion =
if nvidiaVersion != null then
nvidiaVersion
else
# Get if from the nvidiaVersionFile
let
data = builtins.readFile _nvidiaVersionFile;
versionMatch = builtins.match ".*Module +([0-9]+\\.[0-9]+).*" data;
in
assert builtins.length versionMatch == 1;
builtins.head versionMatch;
addNvidiaVersion = drv: drv.overrideAttrs(oldAttrs: { addNvidiaVersion = drv: drv.overrideAttrs(oldAttrs: {
name = oldAttrs.name + "-${_nvidiaVersion}"; name = oldAttrs.name + "-${_nvidiaVersion}";
@ -57,7 +70,6 @@ let
done done
''; '';
}; };
in in
rec { rec {
nvidia = (linuxPackages.nvidia_x11.override { nvidia = (linuxPackages.nvidia_x11.override {