nongnu: nvidia: Update source procedures.

* nongnu/packages/nvidia.scm (nvidia-driver-snippet): New variable.
(nvidia-source): Switch to ‘url-fetch’ and use it.
(nvidia-driver,nvidia-module)[source,arguments]: Adjust accordingly.
(nvidia-settings-source): New procedure.
(nvidia-settings)[source]: Use it.
(nvidia-source-unbundle-libraries,make-nvidia-source): Delete procedures.

Modified-by: Hilton Chain <hako@ultrarare.space>
Signed-off-by: Hilton Chain <hako@ultrarare.space>
This commit is contained in:
Nicolas Graves 2024-07-16 22:50:47 +02:00 committed by Hilton Chain
parent d8c25a0ad2
commit 8a6a4a3982
No known key found for this signature in database
GPG key ID: ACC66D09CA528292

View file

@ -79,11 +79,19 @@
(define %nvidia-settings-hashes (define %nvidia-settings-hashes
'(("550.120" . "1d8rxpk2z9apkvm7vsr7j93rfizh8bgm4h6rlha3m2j818zwixvw"))) '(("550.120" . "1d8rxpk2z9apkvm7vsr7j93rfizh8bgm4h6rlha3m2j818zwixvw")))
(define (nvidia-source-unbundle-libraries version) (define nvidia-driver-snippet
#~(begin ;; Note: delay to cope with cyclic module imports at the top level.
(use-modules (guix build utils)) (delay
(for-each delete-file #~(begin
(find-files "." (string-join (use-modules (guix build utils) (ice-9 ftw) (srfi srfi-1))
(set-path-environment-variable
"PATH" '("bin")
'#+(list bash-minimal coreutils-minimal grep tar zstd))
(let* ((this-file (last (scandir (getcwd)))))
(invoke "sh" this-file "--extract-only" "--target" "extractdir")
(for-each delete-file
(find-files "extractdir"
(string-join
'(;; egl-gbm '(;; egl-gbm
"libnvidia-egl-gbm\\.so\\." "libnvidia-egl-gbm\\.so\\."
;; egl-wayland ;; egl-wayland
@ -100,54 +108,28 @@
"libnvidia-gtk[23]\\.so\\." "libnvidia-gtk[23]\\.so\\."
;; opencl-icd-loader ;; opencl-icd-loader
"libOpenCL\\.so\\.") "libOpenCL\\.so\\.")
"|"))))) "|")))
(with-directory-excursion "extractdir"
(invoke "tar" "cvfa" (string-append this-file ".tar")
"--mtime=1" "--owner=root:0" "--group=root:0" ;determinism
"--sort=name" ".")
(invoke "zstd" (string-append this-file ".tar")))
(rename-file
(string-append "extractdir/" this-file ".tar.zst") this-file)))))
(define* (make-nvidia-source (define (nvidia-source version)
version hash "Given VERSION of an NVIDIA driver installer, return an <origin> for
#:optional (get-cleanup-snippet nvidia-source-unbundle-libraries)) its unpacked checkout."
"Given VERSION and HASH of an NVIDIA driver installer, return an <origin> for
its unpacked checkout. GET-CLEANUP-SNIPPET is a procedure that accepts the
VERSION as argument and returns a G-expression."
(define installer
(origin
(method url-fetch)
(uri (string-append
"https://us.download.nvidia.com/XFree86/Linux-x86_64/"
version "/NVIDIA-Linux-x86_64-" version ".run"))
(sha256 hash)))
(origin (origin
(method (@@ (guix packages) computed-origin-method)) (method url-fetch)
(file-name (string-append "nvidia-driver-" version "-checkout")) (uri (string-append
(sha256 #f) "https://us.download.nvidia.com/XFree86/Linux-x86_64/"
(snippet (get-cleanup-snippet version)) version "/NVIDIA-Linux-x86_64-" version ".run"))
(uri (file-name (string-append "NVIDIA-Linux-x86_64-" version))
(delay (sha256
(with-imported-modules '((guix build utils)) (base32 (assoc-ref %nvidia-driver-hashes version)))
#~(begin (modules '((guix build utils)))
(use-modules (guix build utils) (snippet (force nvidia-driver-snippet))))
(ice-9 ftw))
(set-path-environment-variable
"PATH" '("bin")
'#+(list bash-minimal
coreutils
gawk
grep
tar
which
xz
zstd))
(setenv "XZ_OPT" (string-join (%xz-parallel-args)))
(invoke "sh" #$installer "-x")
(copy-recursively
(car (scandir (canonicalize-path (getcwd))
(lambda (file)
(not (member file '("." ".."))))))
#$output)))))))
(define-public nvidia-source
(make-nvidia-source
nvidia-version
(base32 (assoc-ref %nvidia-driver-hashes nvidia-version))))
;;; ;;;
@ -248,7 +230,7 @@ ACTION==\"unbind\", SUBSYSTEM==\"pci\", ATTR{vendor}==\"0x10de\", ATTR{class}==\
(package (package
(name "nvidia-driver") (name "nvidia-driver")
(version nvidia-version) (version nvidia-version)
(source nvidia-source) (source (nvidia-source version))
(build-system copy-build-system) (build-system copy-build-system)
(arguments (arguments
(list #:modules '((guix build copy-build-system) (list #:modules '((guix build copy-build-system)
@ -274,6 +256,9 @@ ACTION==\"unbind\", SUBSYSTEM==\"pci\", ATTR{vendor}==\"0x10de\", ATTR{class}==\
("nvidia_layers.json" "share/vulkan/implicit_layer.d/")) ("nvidia_layers.json" "share/vulkan/implicit_layer.d/"))
#:phases #:phases
#~(modify-phases %standard-phases #~(modify-phases %standard-phases
(replace 'unpack
(lambda* (#:key source #:allow-other-keys)
(invoke "tar" "xvf" source)))
(delete 'strip) (delete 'strip)
(add-after 'unpack 'create-misc-files (add-after 'unpack 'create-misc-files
(lambda* (#:key inputs #:allow-other-keys) (lambda* (#:key inputs #:allow-other-keys)
@ -476,7 +461,10 @@ mainly used as a dependency of other packages. For user-facing purpose, use
(package-version this-package)))) (package-version this-package))))
#:phases #:phases
#~(modify-phases %standard-phases #~(modify-phases %standard-phases
(delete 'strip)))) (delete 'strip)
(replace 'unpack
(lambda* (#:key source #:allow-other-keys)
(invoke "tar" "xvf" source))))))
(propagated-inputs '()) (propagated-inputs '())
(inputs '()) (inputs '())
(native-inputs '()) (native-inputs '())
@ -500,7 +488,7 @@ To enable GSP mode manually, add @code{\"NVreg_EnableGpuFirmware=1\"} to
(package (package
(name "nvidia-module") (name "nvidia-module")
(version nvidia-version) (version nvidia-version)
(source nvidia-source) (source (nvidia-source version))
(build-system linux-module-build-system) (build-system linux-module-build-system)
(arguments (arguments
(list #:linux linux-lts (list #:linux linux-lts
@ -510,6 +498,9 @@ To enable GSP mode manually, add @code{\"NVreg_EnableGpuFirmware=1\"} to
#~(list (string-append "CC=" #$(cc-for-target))) #~(list (string-append "CC=" #$(cc-for-target)))
#:phases #:phases
#~(modify-phases %standard-phases #~(modify-phases %standard-phases
(replace 'unpack
(lambda* (#:key source #:allow-other-keys)
(invoke "tar" "xvf" source)))
(delete 'strip) (delete 'strip)
(add-before 'configure 'fixpath (add-before 'configure 'fixpath
(lambda* (#:key (source-directory ".") #:allow-other-keys) (lambda* (#:key (source-directory ".") #:allow-other-keys)
@ -576,20 +567,22 @@ add @code{nvidia_drm.modeset=1} to @code{kernel-arguments} as well.")
;;; nvidia-settings packages ;;; nvidia-settings packages
;;; ;;;
(define (nvidia-settings-source name version)
(origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/NVIDIA/nvidia-settings")
(commit version)))
(file-name (git-file-name name version))
(modules '((guix build utils)))
(snippet '(delete-file-recursively "src/jansson"))
(sha256 (base32 (assoc-ref %nvidia-settings-hashes version)))))
(define-public nvidia-settings (define-public nvidia-settings
(package (package
(name "nvidia-settings") (name "nvidia-settings")
(version nvidia-version) (version nvidia-version)
(source (origin (source (nvidia-settings-source name version))
(method git-fetch)
(uri (git-reference
(url "https://github.com/NVIDIA/nvidia-settings")
(commit version)))
(file-name (git-file-name name version))
(modules '((guix build utils)))
(snippet '(delete-file-recursively "src/jansson"))
(sha256 (base32 (assoc-ref %nvidia-settings-hashes version)))))
(build-system gnu-build-system) (build-system gnu-build-system)
(arguments (arguments
(list #:tests? #f ;no test suite (list #:tests? #f ;no test suite