nongnu: nvidia-driver: Don't hardcode inputs.

* nongnu/packages/nvidia.scm (nvidia-driver)[arguments]<#:phases>: Use
G-expression and don't hardcode inputs when possible.

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

View file

@ -87,10 +87,9 @@
#:phases #:phases
#~(modify-phases %standard-phases #~(modify-phases %standard-phases
(replace 'unpack (replace 'unpack
(lambda* (#:key inputs #:allow-other-keys #:rest r) (lambda _
(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
@ -98,14 +97,11 @@
;; would be installed. ;; would be installed.
(chdir "kernel") (chdir "kernel")
;; Patch Kbuild ;; Patch Kbuild
(substitute* "Kbuild" (substitute* "Kbuild" (("/bin/sh") (which "sh")))
(("/bin/sh") (string-append #$bash-minimal "/bin/sh"))) (invoke "make" "-j"
(invoke "make" (string-append "CC=" #$(cc-for-target))
"-j" (string-append "SYSSRC=" (search-input-directory
(string-append "SYSSRC=" inputs "/lib/modules/build")))))
(assoc-ref inputs "linux-module-builder")
"/lib/modules/build")
"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)
@ -126,7 +122,7 @@
(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." #$(package-version nvidia-driver)) (install-file (string-append "libglxserver_nvidia.so." #$version)
(string-append #$output "/lib/xorg/modules/extensions/")) (string-append #$output "/lib/xorg/modules/extensions/"))
;; ICD Loader for OpenCL ;; ICD Loader for OpenCL
@ -140,10 +136,10 @@
;; 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 (search-input-file inputs "/bin/sh"))
(mknod (string-append #$coreutils "/bin/mknod")) (mknod (search-input-file inputs "/bin/mknod"))
(cut (string-append #$coreutils "/bin/cut")) (cut (search-input-file inputs "/bin/cut"))
(grep (string-append #$grep "/bin/grep"))) (grep (search-input-file inputs "/bin/grep")))
(mkdir-p rulesdir) (mkdir-p rulesdir)
(call-with-output-file rules (call-with-output-file rules
(lambda (port) (lambda (port)
@ -167,7 +163,7 @@
(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 "#!" (search-input-file inputs "/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"
@ -177,7 +173,7 @@
(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 "#!" (search-input-file inputs "/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"
@ -192,23 +188,23 @@
;; ------------------------------ ;; ------------------------------
;; patchelf ;; patchelf
(let* ((ld.so (string-append #$glibc #$(glibc-dynamic-linker))) (let* ((ld.so (string-append #$(this-package-input "glibc")
#$(glibc-dynamic-linker)))
(rpath (string-join (rpath (string-join
(list "$ORIGIN" (list "$ORIGIN"
(string-append #$output "/lib") (string-append #$output "/lib")
(string-append #$gcc:lib "/lib") (string-append #$gcc:lib "/lib")
(string-append #$gtk+-2 "/lib") (string-append #$gtk+-2 "/lib")
(string-append #$atk "/lib") (string-append #$(this-package-input "atk") "/lib")
(string-append #$cairo "/lib") (string-append #$(this-package-input "cairo") "/lib")
(string-append #$gdk-pixbuf "/lib") (string-append #$(this-package-input "gdk-pixbuf") "/lib")
(string-append #$glib "/lib") (string-append #$(this-package-input "glib") "/lib")
(string-append #$glibc "/lib") (string-append #$(this-package-input "glibc") "/lib")
(string-append #$gtk+ "/lib") (string-append #$(this-package-input "gtk+") "/lib")
(string-append #$libx11 "/lib") (string-append #$(this-package-input "libx11") "/lib")
(string-append #$libxext "/lib") (string-append #$(this-package-input "libxext") "/lib")
(string-append #$pango "/lib") (string-append #$(this-package-input "pango") "/lib")
(string-append #$wayland "/lib")) (string-append #$(this-package-input "wayland") "/lib"))
":"))) ":")))
(define (patch-elf file) (define (patch-elf file)
(format #t "Patching ~a ...~%" file) (format #t "Patching ~a ...~%" file)
@ -247,7 +243,7 @@
(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." #$(package-version nvidia-driver)) (symlink (string-append "libglxserver_nvidia.so." #$version)
(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 (list patchelf perl python-2 which xz)) (native-inputs (list patchelf perl python-2 which xz))