nongnu: nvidia-driver: Fix indentation.

* nongnu/packages/nvidia.scm (nvidia-driver): Fix indentation.
[inputs,native-inputs]: Sort alphabetically.

Signed-off-by: Jonathan Brielmaier <jonathan.brielmaier@web.de>
This commit is contained in:
Hilton Chain 2022-11-20 21:15:40 +08:00 committed by Jonathan Brielmaier
parent 370749ab7b
commit 1544351697
No known key found for this signature in database
GPG key ID: ECFC83988B4E4B9F

View file

@ -6,6 +6,7 @@
;;; Copyright © 2021 Pierre Langlois <pierre.langlois@gmx.com> ;;; Copyright © 2021 Pierre Langlois <pierre.langlois@gmx.com>
;;; Copyright © 2022 Petr Hodina <phodina@protonmail.com> ;;; Copyright © 2022 Petr Hodina <phodina@protonmail.com>
;;; Copyright © 2022 Alexey Abramov <levenson@mmer.org> ;;; Copyright © 2022 Alexey Abramov <levenson@mmer.org>
;;; Copyright © 2022 Hilton Chain <hako@ultrarare.space>
;;; ;;;
;;; This file is not part of GNU Guix. ;;; This file is not part of GNU Guix.
;;; ;;;
@ -82,210 +83,203 @@
(build-system linux-module-build-system) (build-system linux-module-build-system)
(arguments (arguments
(list #:linux linux-lts (list #:linux linux-lts
#:tests? #f #:tests? #f
#:phases #:phases
#~(modify-phases %standard-phases #~(modify-phases %standard-phases
(replace 'unpack (replace 'unpack
(lambda* (#:key inputs #:allow-other-keys #:rest r) (lambda* (#:key inputs #:allow-other-keys #:rest r)
(let ((source (assoc-ref inputs "source"))) (let ((source (assoc-ref inputs "source")))
(invoke "sh" source "--extract-only") (invoke "sh" source "--extract-only")
(chdir #$(format #f "NVIDIA-Linux-x86_64-~a" version))))) (chdir #$(format #f "NVIDIA-Linux-x86_64-~a" version)))))
(replace 'build (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 ;; We cannot use with-directory-excursion, because the install
;; phase needs to be in the kernel folder. Otherwise no .ko ;; phase needs to be in the kernel folder. Otherwise no .ko
;; would be installed. ;; would be installed.
(chdir "kernel") (chdir "kernel")
;; Patch Kbuild ;; Patch Kbuild
(substitute* "Kbuild" (substitute* "Kbuild"
(("/bin/sh") (string-append #$bash-minimal "/bin/sh"))) (("/bin/sh") (string-append #$bash-minimal "/bin/sh")))
(invoke "make" (invoke "make"
"-j" "-j"
(string-append "SYSSRC=" (string-append "SYSSRC="
(assoc-ref inputs "linux-module-builder") (assoc-ref inputs "linux-module-builder")
"/lib/modules/build") "/lib/modules/build")
"CC=gcc"))) "CC=gcc")))
(delete 'strip) (delete 'strip)
(add-after 'install 'install-copy (add-after 'install 'install-copy
(lambda* (#:key inputs native-inputs outputs #:allow-other-keys) (lambda* (#:key inputs native-inputs outputs #:allow-other-keys)
(chdir "..") (chdir "..")
(use-modules (ice-9 ftw) (use-modules (ice-9 ftw)
(ice-9 regex) (ice-9 regex)
(ice-9 textual-ports)) (ice-9 textual-ports))
(let* ((libdir (string-append #$output "/lib")) (let* ((libdir (string-append #$output "/lib"))
(bindir (string-append #$output "/bin")) (bindir (string-append #$output "/bin"))
(etcdir (string-append #$output "/etc"))) (etcdir (string-append #$output "/etc")))
;; ------------------------------ ;; ------------------------------
;; Copy .so files ;; Copy .so files
(for-each (for-each
(lambda (file) (lambda (file)
(format #t "Copying '~a'...~%" file) (format #t "Copying '~a'...~%" file)
(install-file file libdir)) (install-file file libdir))
(scandir "." (lambda (name) (scandir "." (lambda (name)
(string-contains name ".so")))) (string-contains name ".so"))))
(install-file "nvidia_drv.so" (string-append #$output "/lib/xorg/modules/drivers/")) (install-file "nvidia_drv.so" (string-append #$output "/lib/xorg/modules/drivers/"))
(install-file (string-append "libglxserver_nvidia.so." (install-file (string-append "libglxserver_nvidia.so." #$(package-version nvidia-driver))
#$(package-version nvidia-driver)) (string-append #$output "/lib/xorg/modules/extensions/"))
(string-append #$output "/lib/xorg/modules/extensions/"))
;; ICD Loader for OpenCL ;; ICD Loader for OpenCL
(let ((file (string-append etcdir "/OpenCL/vendors/nvidia.icd"))) (let ((file (string-append etcdir "/OpenCL/vendors/nvidia.icd")))
(mkdir-p (string-append etcdir "/OpenCL/vendors/")) (mkdir-p (string-append etcdir "/OpenCL/vendors/"))
(call-with-output-file file (call-with-output-file file
(lambda (port) (lambda (port)
(display (string-append #$output "/lib/libnvidia-opencl.so.1") port))) (display (string-append #$output "/lib/libnvidia-opencl.so.1") port)))
(chmod file #o555)) (chmod file #o555))
;; Add udev rules for nvidia ;; Add udev rules for nvidia
(let ((rulesdir (string-append #$output "/lib/udev/rules.d/")) (let ((rulesdir (string-append #$output "/lib/udev/rules.d/"))
(rules (string-append #$output "/lib/udev/rules.d/90-nvidia.rules")) (rules (string-append #$output "/lib/udev/rules.d/90-nvidia.rules"))
(sh (string-append #$bash-minimal "/bin/sh")) (sh (string-append #$bash-minimal "/bin/sh"))
(mknod (string-append #$coreutils "/bin/mknod")) (mknod (string-append #$coreutils "/bin/mknod"))
(cut (string-append #$coreutils "/bin/cut")) (cut (string-append #$coreutils "/bin/cut"))
(grep (string-append #$grep "/bin/grep"))) (grep (string-append #$grep "/bin/grep")))
(mkdir-p rulesdir) (mkdir-p rulesdir)
(call-with-output-file rules (call-with-output-file rules
(lambda (port) (lambda (port)
(put-string port (put-string port
(string-append (string-append
"KERNEL==\"nvidia\", " "KERNEL==\"nvidia\", "
"RUN+=\"" sh " -c '" mknod " -m 666 /dev/nvidiactl c $$(" grep " nvidia-frontend /proc/devices | " cut " -d \\ -f 1) 255'\"" "\n" "RUN+=\"" sh " -c '" mknod " -m 666 /dev/nvidiactl c $$(" grep " nvidia-frontend /proc/devices | " cut " -d \\ -f 1) 255'\"" "\n"
"KERNEL==\"nvidia_modeset\", " "KERNEL==\"nvidia_modeset\", "
"RUN+=\"" sh " -c '" mknod " -m 666 /dev/nvidia-modeset c $$(" grep " nvidia-frontend /proc/devices | " cut " -d \\ -f 1) 254'\"" "\n" "RUN+=\"" sh " -c '" mknod " -m 666 /dev/nvidia-modeset c $$(" grep " nvidia-frontend /proc/devices | " cut " -d \\ -f 1) 254'\"" "\n"
"KERNEL==\"card*\", SUBSYSTEM==\"drm\", DRIVERS==\"nvidia\", " "KERNEL==\"card*\", SUBSYSTEM==\"drm\", DRIVERS==\"nvidia\", "
"RUN+=\"" sh " -c '" mknod " -m 666 /dev/nvidia0 c $$(" grep " nvidia-frontend /proc/devices | " cut " -d \\ -f 1) 0'\"" "\n" "RUN+=\"" sh " -c '" mknod " -m 666 /dev/nvidia0 c $$(" grep " nvidia-frontend /proc/devices | " cut " -d \\ -f 1) 0'\"" "\n"
"KERNEL==\"nvidia_uvm\", " "KERNEL==\"nvidia_uvm\", "
"RUN+=\"" sh " -c '" mknod " -m 666 /dev/nvidia-uvm c $$(" grep " nvidia-uvm /proc/devices | " cut " -d \\ -f 1) 0'\"" "\n" "RUN+=\"" sh " -c '" mknod " -m 666 /dev/nvidia-uvm c $$(" grep " nvidia-uvm /proc/devices | " cut " -d \\ -f 1) 0'\"" "\n"
"KERNEL==\"nvidia_uvm\", " "KERNEL==\"nvidia_uvm\", "
"RUN+=\"" sh " -c '" mknod " -m 666 /dev/nvidia-uvm-tools c $$(" grep " nvidia-uvm /proc/devices | " cut " -d \\ -f 1) 0'\"" "\n" ))))) "RUN+=\"" sh " -c '" mknod " -m 666 /dev/nvidia-uvm-tools c $$(" grep " nvidia-uvm /proc/devices | " cut " -d \\ -f 1) 0'\"" "\n" )))))
;; ------------------------------ ;; ------------------------------
;; Add a file to load nvidia drivers ;; Add a file to load nvidia drivers
(mkdir-p bindir) (mkdir-p bindir)
(let ((file (string-append bindir "/nvidia-insmod")) (let ((file (string-append bindir "/nvidia-insmod"))
(moddir (string-append "/lib/modules/" (utsname:release (uname)) "-gnu/extra"))) (moddir (string-append "/lib/modules/" (utsname:release (uname)) "-gnu/extra")))
(call-with-output-file file (call-with-output-file file
(lambda (port) (lambda (port)
(put-string port (string-append "#!" (assoc-ref inputs "bash-minimal") "/bin/sh" "\n" (put-string port (string-append "#!" (assoc-ref inputs "bash-minimal") "/bin/sh" "\n"
"modprobe ipmi_devintf" "\n" "modprobe ipmi_devintf" "\n"
"insmod " #$output moddir "/nvidia.ko" "\n" "insmod " #$output moddir "/nvidia.ko" "\n"
"insmod " #$output moddir "/nvidia-modeset.ko" "\n" "insmod " #$output moddir "/nvidia-modeset.ko" "\n"
"insmod " #$output moddir "/nvidia-uvm.ko" "\n" "insmod " #$output moddir "/nvidia-uvm.ko" "\n"
"insmod " #$output moddir "/nvidia-drm.ko" "\n")))) "insmod " #$output moddir "/nvidia-drm.ko" "\n"))))
(chmod file #o555)) (chmod file #o555))
(let ((file (string-append bindir "/nvidia-rmmod"))) (let ((file (string-append bindir "/nvidia-rmmod")))
(call-with-output-file file (call-with-output-file file
(lambda (port) (lambda (port)
(put-string port (string-append "#!" #$bash-minimal "/bin/sh" "\n" (put-string port (string-append "#!" #$bash-minimal "/bin/sh" "\n"
"rmmod " "nvidia-drm" "\n" "rmmod " "nvidia-drm" "\n"
"rmmod " "nvidia-uvm" "\n" "rmmod " "nvidia-uvm" "\n"
"rmmod " "nvidia-modeset" "\n" "rmmod " "nvidia-modeset" "\n"
"rmmod " "nvidia" "\n" "rmmod " "nvidia" "\n"
"rmmod " "ipmi_devintf" "\n")))) "rmmod " "ipmi_devintf" "\n"))))
(chmod file #o555)) (chmod file #o555))
;; ------------------------------ ;; ------------------------------
;; nvidia-smi ;; nvidia-smi
(install-file "nvidia-smi" bindir) (install-file "nvidia-smi" bindir)
;; ------------------------------ ;; ------------------------------
;; patchelf ;; patchelf
(let* ((ld.so (string-append #$glibc #$(glibc-dynamic-linker))) (let* ((ld.so (string-append #$glibc #$(glibc-dynamic-linker)))
(rpath (string-join (rpath (string-join
(list "$ORIGIN" (list "$ORIGIN"
(string-append #$output "/lib") (string-append #$output "/lib")
(string-append #$glibc "/lib") (string-append #$gcc:lib "/lib")
(string-append #$libx11 "/lib") (string-append #$gtk+-2 "/lib")
(string-append #$libxext "/lib") (string-append #$atk "/lib")
(string-append #$pango "/lib") (string-append #$cairo "/lib")
(string-append #$gtk+ "/lib") (string-append #$gdk-pixbuf "/lib")
(string-append #$gtk+-2 "/lib") (string-append #$glib "/lib")
(string-append #$atk "/lib") (string-append #$glibc "/lib")
(string-append #$glib "/lib") (string-append #$gtk+ "/lib")
(string-append #$cairo "/lib") (string-append #$libx11 "/lib")
(string-append #$gdk-pixbuf "/lib") (string-append #$libxext "/lib")
(string-append #$wayland "/lib") (string-append #$pango "/lib")
(string-append #$gcc:lib "/lib")) (string-append #$wayland "/lib"))
":"))) ":")))
(define (patch-elf file) (define (patch-elf file)
(format #t "Patching ~a ...~%" file) (format #t "Patching ~a ...~%" file)
(unless (string-contains file ".so") (unless (string-contains file ".so")
(invoke "patchelf" "--set-interpreter" ld.so file)) (invoke "patchelf" "--set-interpreter" ld.so file))
(invoke "patchelf" "--set-rpath" rpath file)) (invoke "patchelf" "--set-rpath" rpath file))
(for-each (lambda (file) (for-each (lambda (file)
(when (elf-file? file) (when (elf-file? file)
(patch-elf file))) (patch-elf file)))
(find-files #$output ".*\\.so")) (find-files #$output ".*\\.so"))
(patch-elf (string-append bindir "/" "nvidia-smi"))) (patch-elf (string-append bindir "/" "nvidia-smi")))
;; ------------------------------ ;; ------------------------------
;; Create short name symbolic links ;; Create short name symbolic links
(for-each (lambda (file) (for-each (lambda (file)
(let* ((short (regexp-substitute (let* ((short (regexp-substitute
#f #f
(string-match "([^/]*\\.so).*" file) (string-match "([^/]*\\.so).*" file)
1)) 1))
(major (cond (major (cond
((or (string=? short "libGLX.so") ((or (string=? short "libGLX.so")
(string=? short "libGLX_nvidia.so") (string=? short "libGLX_nvidia.so")
(string=? short "libEGL_nvidia.so")) "0") (string=? short "libEGL_nvidia.so")) "0")
((string=? short "libGLESv2.so") "2") ((string=? short "libGLESv2.so") "2")
(else "1"))) (else "1")))
(mid (string-append short "." major)) (mid (string-append short "." major))
(short-file (string-append libdir "/" short)) (short-file (string-append libdir "/" short))
(mid-file (string-append libdir "/" mid))) (mid-file (string-append libdir "/" mid)))
;; FIXME the same name, print out warning at least ;; FIXME the same name, print out warning at least
;; [X] libEGL.so.1.1.0 ;; [X] libEGL.so.1.1.0
;; [ ] libEGL.so.435.21 ;; [ ] libEGL.so.435.21
(when (not (file-exists? short-file)) (when (not (file-exists? short-file))
(format #t "Linking ~a to ~a ...~%" short file) (format #t "Linking ~a to ~a ...~%" short file)
(symlink (basename file) short-file)) (symlink (basename file) short-file))
(when (not (file-exists? mid-file)) (when (not (file-exists? mid-file))
(format #t "Linking ~a to ~a ...~%" mid file) (format #t "Linking ~a to ~a ...~%" mid file)
(symlink (basename file) mid-file)))) (symlink (basename file) mid-file))))
(find-files libdir "\\.so\\.")) (find-files libdir "\\.so\\."))
(symlink (string-append "libglxserver_nvidia.so." (symlink (string-append "libglxserver_nvidia.so." #$(package-version nvidia-driver))
#$(package-version nvidia-driver)) (string-append #$output "/lib/xorg/modules/extensions/" "libglxserver_nvidia.so"))))))))
(string-append #$output "/lib/xorg/modules/extensions/" "libglxserver_nvidia.so"))))))))
(supported-systems '("x86_64-linux")) (supported-systems '("x86_64-linux"))
(native-inputs (native-inputs (list patchelf perl python-2 which xz))
(list
patchelf
perl
python-2
which
xz))
(inputs (inputs
(list (list `(,gcc "lib")
atk atk
bash-minimal bash-minimal
cairo cairo
coreutils coreutils
`(,gcc "lib") gdk-pixbuf
gdk-pixbuf glib
glib glibc
grep grep
gtk+ gtk+
gtk+-2 gtk+-2
kmod kmod
glibc libx11
libx11 libxext
libxext linux-lts
linux-lts pango
pango wayland))
wayland))
(home-page "https://www.nvidia.com") (home-page "https://www.nvidia.com")
(synopsis "Proprietary Nvidia driver") (synopsis "Proprietary NVIDIA driver")
(description "This is the evil Nvidia driver. Don't forget to add (description "This is the evil NVIDIA driver. Don't forget to add
nvidia-driver to the udev-rules in your config.scm: @code{nvidia-driver} to the @code{udev-rules} in your @file{config.scm}:
@code{(simple-service 'custom-udev-rules udev-service-type (list nvidia-driver))} @code{(simple-service 'custom-udev-rules udev-service-type (list
Further xorg should be configured by adding: nvidia-driver))}. Further xorg should be configured by adding: @code{(modules
@code{(modules (cons* nvidia-driver %default-xorg-modules)) (cons* nvidia-driver %default-xorg-modules)) (drivers '(\"nvidia\"))} to
(drivers '(\"nvidia\"))} to @code{xorg-configuration}.") @code{xorg-configuration}.")
(license (license:nonfree (format #f "file:///share/doc/nvidia-driver-~a/LICENSE" version))))) (license
(license:nonfree
(format #f "file:///share/doc/nvidia-driver-~a/LICENSE" version)))))
(define-public nvidia-exec (define-public nvidia-exec
(package (package