Merge branch 'master' into 'master'

DRAFT: #166: nongnu: nvidia: Add wayland-native vulkan rendering ; nvidia_icd.json

See merge request nonguix/nonguix!160
This commit is contained in:
Samuel Culpepper 2022-03-22 16:22:59 +00:00
commit 8c1dc5c3b0

View File

@ -21,6 +21,7 @@
;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(define-module (nongnu packages nvidia)
#:use-module (gnu packages xdisorg)
#:use-module (guix packages)
#:use-module (guix download)
#:use-module (guix utils)
@ -54,13 +55,13 @@
(define-public nvidia-driver
(package
(name "nvidia-driver")
(version "470.86")
(version "495.46")
(source
(origin
(uri (format #f "http://us.download.nvidia.com/XFree86/Linux-x86_64/~a/~a.run"
version
(format #f "NVIDIA-Linux-x86_64-~a" version)))
(sha256 (base32 "0krwcxc0j19vjnk8sv6mx1lin2rm8hcfhc2hg266846jvcws1dsg"))
(sha256 (base32 "1xb23kimlfsailpwy7kv4l217id5jpmdc4svm9kldid0gp8pffyq"))
(method url-fetch)
(file-name (string-append "nvidia-driver-" version "-checkout"))))
(build-system linux-module-build-system)
@ -75,10 +76,20 @@
(chdir ,(format #f "NVIDIA-Linux-x86_64-~a" version))
#t)))
(replace 'build
(lambda* (#:key inputs outputs #:allow-other-keys)
(lambda* (#:key inputs outputs #:allow-other-keys)
;; We cannot use with-directory-excursion, because the install
;; phase needs to be in the kernel folder. Otherwise no .ko
;; would be installed.
;;
;; NOTE: new in 495 nvidia-drm.ko
;; see Chapter 35 "Direct Rendering Manager Kernel Modesetting (DRM KMS)"
;; - PRIME offload: CONFIG_DRM enabled
;; - Atomic Modeset: non-X11: CONFIG_DRM, CONFIG_DRM_KMS_HELPER enabled
;; modprobe -r nvidia_drm ; modprobe nvidia_drm modeset=1
;; caveats: ( 495.46 >= )
;; - DRM KMS cannot use SLI mosaic
;; - no overlay plane, only primary & cursor
;; - allocation/submission to DRM KMS is not possible with GBM
(chdir "kernel")
;; Patch Kbuild
(substitute* "Kbuild"
@ -102,6 +113,7 @@
(libdir (string-append out "/lib"))
(bindir (string-append out "/bin"))
(etcdir (string-append out "/etc")))
;; ------------------------------
;; Copy .so files
(for-each
@ -111,9 +123,42 @@
(scandir "." (lambda (name)
(string-contains name ".so"))))
(install-file "nvidia_drv.so" (string-append out "/lib/xorg/modules/drivers/"))
(install-file ,(string-append "libglxserver_nvidia.so." version) (string-append out "/lib/xorg/modules/extensions/"))
(install-file "nvidia_drv.so"
(string-append out "/lib/xorg/modules/drivers/"))
(install-file ,(string-append "libglxserver_nvidia.so." version)
(string-append out "/lib/xorg/modules/extensions/"))
;; ------------------------------
;; Copy .json files
(for-each
(lambda (file)
(let ((dest (assoc file
'(("nvidia_icd.json" . "vulkan/icd.d")
("nvidia_layers.json" . "vulkan/explicit_layer.d")
("10_nvidia.json" . "glvnd/egl_vendor.d")
("10_nvidia_wayland.json" . "glvnd/egl_external_platform.d")
("15_nvidia_gbm.json" . "glvnd/egl_external_platform.d")))))
(when dest
(format #t "Copying '~a' -> '~a' ...~%" file (cdr dest))
(install-file file (string-append out "/" (cdr dest))))))
(scandir "." (lambda (name)
(string-contains name ".json"))))
(use-modules (ice-9 string-fun))
(let* ((outdir (string-append out "/vulkan/icd.d"))
(outfile (string-append outdir "/nvidia_icd.json")))
(mkdir-p outdir)
(call-with-output-file outfile
(lambda (port)
(put-string
port (call-with-input-file "nvidia_icd.json"
(lambda (source)
(string-replace-substring
(get-string-all source)
"libGLX_nvidia.so.0"
"libEGL_nvidia.so.0")))))))
;; ------------------------------
;; ICD Loader for OpenCL
(let ((file (string-append etcdir "/OpenCL/vendors/nvidia.icd")))
(mkdir-p (string-append etcdir "/OpenCL/vendors/"))
@ -122,12 +167,13 @@
(display (string-append out "/lib/libnvidia-opencl.so.1") port)))
(chmod file #o555))
;; ------------------------------
;; Add udev rules for nvidia
(let ((rulesdir (string-append out "/lib/udev/rules.d/"))
(rules (string-append out "/lib/udev/rules.d/90-nvidia.rules"))
(sh (string-append (assoc-ref inputs "bash-minimal") "/bin/sh"))
(mknod (string-append (assoc-ref inputs "coreutils") "/bin/mknod"))
(cut (string-append (assoc-ref inputs "coreutils") "/bin/cut"))
(cut (string-append (assoc-ref inputs "coreutils") "/bin/cut"))
(grep (string-append (assoc-ref inputs "grep") "/bin/grep")))
(mkdir-p rulesdir)
(call-with-output-file rules
@ -173,7 +219,6 @@
;; ------------------------------
;; nvidia-smi
(install-file "nvidia-smi" bindir)
;; ------------------------------
@ -196,6 +241,9 @@
(string-append (assoc-ref inputs "cairo") "/lib")
(string-append (assoc-ref inputs "gdk-pixbuf") "/lib")
(string-append (assoc-ref inputs "wayland") "/lib")
(string-append (assoc-ref inputs "libdrm") "/lib") ; libdrm.so
;; mesa >= 21.2 provids libgbm.so.1 -- see 39B "REQUIREMENTS"
(string-append (assoc-ref inputs "mesa") "/lib")
(string-append (assoc-ref inputs "gcc:lib") "/lib"))
":")))
(define (patch-elf file)
@ -236,7 +284,20 @@
(symlink (basename file) mid-file))))
(find-files libdir "\\.so\\."))
(symlink ,(string-append "libglxserver_nvidia.so." version)
(string-append out "/lib/xorg/modules/extensions/" "libglxserver_nvidia.so")))
(string-append out "/lib/xorg/modules/extensions/" "libglxserver_nvidia.so"))
;; ------------------------------
;; Install GBM backend
;;
;; export GBM_BACKENDS_PATH=/gnu/store/...-nvidia-driver-VERSION/lib/gbm/nvidia-drm_gbm.so
;; see [2/2] https://github.com/Frogging-Family/nvidia-all/commit/ef12a70f293cb23b35205503eab4de63af52305d
;; see [1/2] https://github.com/Frogging-Family/nvidia-all/commit/9404b959dce5152da15afb5b9cda4907c3492e8d
;; see [0/2] https://github.com/Frogging-Family/nvidia-all/commit/e7b6638d4640a490e365387a6351d162c8c69cdd
(let* ((old (string-append out "/lib/libnvidia-allocator.so." ,version))
(new (string-append out "/lib/gbm/nvidia-drm_gbm.so")))
(mkdir (string-append out "/lib/gbm"))
(format #t "SYMLINK ~a -> ~a~%" old new)
(symlink old new)))
#t)))))
(supported-systems '("x86_64-linux"))
(native-inputs
@ -258,6 +319,8 @@
("gtk2" ,gtk+-2)
("kmod" ,kmod)
("libc" ,glibc)
("libdrm" ,libdrm)
("mesa" ,mesa)
("libx11" ,libx11)
("libxext" ,libxext)
("linux" ,linux-lts)
@ -276,13 +339,13 @@ Further xorg should be configured by adding:
(define-public nvidia-libs
(package
(name "nvidia-libs")
(version "470.86")
(version "495.46")
(source
(origin
(uri (format #f "http://us.download.nvidia.com/XFree86/Linux-x86_64/~a/~a.run"
version
(format #f "NVIDIA-Linux-x86_64-~a" version)))
(sha256 (base32 "0krwcxc0j19vjnk8sv6mx1lin2rm8hcfhc2hg266846jvcws1dsg"))
(sha256 (base32 "1xb23kimlfsailpwy7kv4l217id5jpmdc4svm9kldid0gp8pffyq"))
(method url-fetch)
(file-name (string-append "nvidia-driver-" version "-checkout"))))
(build-system copy-build-system)
@ -298,7 +361,7 @@ Further xorg should be configured by adding:
(delete 'build)
(delete 'check)
(add-after 'install 'patch-symlink
(lambda* (#:key inputs native-inputs outputs #:allow-other-keys)
(lambda* (#:key inputs native-inputs outputs #:allow-other-keys)
(use-modules (ice-9 ftw)
(ice-9 regex)
(ice-9 textual-ports))
@ -326,6 +389,8 @@ Further xorg should be configured by adding:
(string-append (assoc-ref inputs "libx11") "/lib")
(string-append (assoc-ref inputs "libxext") "/lib")
(string-append (assoc-ref inputs "pango") "/lib")
(string-append (assoc-ref inputs "libdrm") "/lib") ; libdrm.so
(string-append (assoc-ref inputs "mesa") "/lib") ; libgbm.so
(string-append (assoc-ref inputs "wayland") "/lib"))
":")))
(define (patch-elf file)
@ -343,7 +408,6 @@ Further xorg should be configured by adding:
(for-each (lambda (file)
(let* ((short (regexp-substitute
#f
(string-match "([^/]*\\.so).*" file)
1))
(major (cond
@ -365,9 +429,9 @@ Further xorg should be configured by adding:
(format #t "Linking ~a to ~a ...~%" mid file)
(symlink (basename file) mid-file))))
(find-files libdir "\\.so\\."))
#t))))
#t))))
#:install-plan
,@(match (%current-system)
,@(match (%current-system)
("x86_64-linux" '(`(("." "lib" #:include-regexp ("^./[^/]+\\.so")))))
("i686-linux" '(`(("32" "lib" #:include-regexp ("^./[^/]+\\.so")))))
(_ '()))))
@ -388,14 +452,15 @@ Further xorg should be configured by adding:
("gtk2" ,gtk+-2)
("libc" ,glibc)
("libx11" ,libx11)
("libdrm" ,libdrm)
("mesa" ,mesa)
("libxext" ,libxext)
("wayland" ,wayland)))
(home-page "https://www.nvidia.com")
(synopsis "Libraries of the proprietary Nvidia driver")
(description "These are the libraries of the evil Nvidia driver compatible
with the ones usually provided by Mesa. To use these libraries with
packages that have been compiled with a mesa output, take a look at the nvda
package.")
(description "These are the libraries of the evil Nvidia driver compatible with the ones
usually provided by Mesa. To use these libraries with packages that have been
compiled with a mesa output, take a look at the nvda package.")
(license (license:nonfree (format #f "file:///share/doc/nvidia-driver-~a/LICENSE" version)))))
;; nvda is used as a name because it has the same length as mesa which is
@ -408,22 +473,27 @@ package.")
(build-system trivial-build-system)
(arguments
'(#:modules ((guix build union))
#:builder (begin
(use-modules (guix build union)
(srfi srfi-1)
(ice-9 regex))
(union-build (assoc-ref %outputs "out")
(list (assoc-ref %build-inputs "mesa") (assoc-ref %build-inputs "nvidia-libs"))
#:resolve-collision (lambda (files) (let ((file
(if (string-match "nvidia-libs" (first files))
(first files)
(last files))))
(format #t "chosen ~a ~%" file)
file)))
#t)))
#:builder
(begin
(use-modules (guix build union)
(srfi srfi-1)
(ice-9 regex))
(union-build (assoc-ref %outputs "out")
(list (assoc-ref %build-inputs "mesa")
(assoc-ref %build-inputs "nvidia-libs"))
#:resolve-collision
(lambda (files)
(let ((file
(if (string-match "nvidia-libs" (first files))
(first files)
(last files))))
(format #t "library collision: chosen ~a ~%" file)
file)))
#t)))
(description "These are the libraries of the evil Nvidia driver,
packaged in such a way that you can use the transformation option
@code{--with-graft=mesa=nvda} to use the nvidia driver with a package that requires mesa.")
@code{--with-graft=mesa=nvda} to use the nvidia driver with a package that
requires mesa.")
(inputs
`(("nvidia-libs" ,nvidia-libs)
("mesa" ,mesa)))