diff options
Diffstat (limited to 'nongnu/packages/nvidia.scm')
-rw-r--r-- | nongnu/packages/nvidia.scm | 1362 |
1 files changed, 875 insertions, 487 deletions
diff --git a/nongnu/packages/nvidia.scm b/nongnu/packages/nvidia.scm index b7f2e4b..2c6495e 100644 --- a/nongnu/packages/nvidia.scm +++ b/nongnu/packages/nvidia.scm @@ -1,29 +1,16 @@ -;;; GNU Guix --- Functional package management for GNU +;;; SPDX-License-Identifier: GPL-3.0-or-later ;;; Copyright © 2020 Hebi Li <hebi@lihebi.com> ;;; Copyright © 2020 Malte Frank Gerdes <malte.f.gerdes@gmail.com> ;;; Copyright © 2020, 2021 Jean-Baptiste Volatier <jbv@pm.me> ;;; Copyright © 2020-2022 Jonathan Brielmaier <jonathan.brielmaier@web.de> ;;; Copyright © 2021 Pierre Langlois <pierre.langlois@gmx.com> -;;; Copyright © 2022 Petr Hodina <phodina@protonmail.com> +;;; Copyright © 2022, 2023 Petr Hodina <phodina@protonmail.com> ;;; Copyright © 2022 Alexey Abramov <levenson@mmer.org> -;;; -;;; This file is not part of GNU Guix. -;;; -;;; This program is free software: you can redistribute it and/or modify -;;; it under the terms of the GNU General Public License as published by -;;; the Free Software Foundation, either version 3 of the License, or -;;; (at your option) any later version. -;;; -;;; This program is distributed in the hope that it will be useful, -;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;;; GNU General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with this program. If not, see <https://www.gnu.org/licenses/>. +;;; Copyright © 2022, 2023, 2024 Hilton Chain <hako@ultrarare.space> (define-module (nongnu packages nvidia) #:use-module (guix packages) + #:use-module (guix deprecation) #:use-module (guix download) #:use-module (guix gexp) #:use-module (guix git-download) @@ -31,15 +18,19 @@ #:use-module ((guix licenses) #:prefix license-gnu:) #:use-module ((nonguix licenses) #:prefix license:) #:use-module (guix build-system linux-module) + #:use-module (guix build-system cmake) #:use-module (guix build-system copy) #:use-module (guix build-system gnu) + #:use-module (guix build-system python) #:use-module (guix build-system trivial) #:use-module (gnu packages base) #:use-module (gnu packages bash) #:use-module (gnu packages bootstrap) + #:use-module (gnu packages check) #:use-module (gnu packages compression) #:use-module (gnu packages elf) #:use-module (gnu packages freedesktop) + #:use-module (gnu packages gawk) #:use-module (gnu packages gcc) #:use-module (gnu packages gl) #:use-module (gnu packages glib) @@ -47,245 +38,773 @@ #:use-module (gnu packages linux) #:use-module (gnu packages m4) #:use-module (gnu packages lsof) - #:use-module (gnu packages perl) #:use-module (gnu packages pkg-config) - #:use-module (gnu packages python) + #:use-module (gnu packages python-xyz) + #:use-module (gnu packages qt) + #:use-module (gnu packages tls) #:use-module (gnu packages video) #:use-module (gnu packages web) + #:use-module (gnu packages xdisorg) + #:use-module (gnu packages xml) #:use-module (gnu packages xorg) #:use-module (nongnu packages linux) - #:use-module (ice-9 match) - #:use-module (ice-9 regex) - #:use-module (ice-9 format) - #:use-module (ice-9 textual-ports) - #:use-module (ice-9 match) - #:use-module (srfi srfi-1)) + #:use-module (ice-9 match)) + +(define-public %nvidia-environment-variable-regexps + '("^__GL_" ; NVIDIA OpenGL settings. + "^__GLX_VENDOR_LIBRARY_NAME$" ; For GLVND. + ;; NVIDIA PRIME Render Offload. + "^__NV_PRIME_RENDER_OFFLOAD(_PROVIDER)?$" + "^__VK_LAYER_NV_optimus$" + ;; NVIDIA NGX. + "^__NGX_CONF_FILE$" + "^__NV_SIGNED_LOAD_CHECK$" + "^PROTON_ENABLE_NGX_UPDATER$" + ;; NVIDIA VDPAU settings. + "^VDPAU_NVIDIA_" + ;; GSYNC control for Vulkan direct-to-display applications. + "^VKDirectGSYNC(Compatible)?Allowed$")) + +(define-public nvidia-version "550.67") + + +;;; +;;; NVIDIA driver checkouts +;;; + + +(define* (nvidia-source-hash version #:optional (package "nvidia-driver")) + (define %nvidia-source-hashes + '(("550.67" . + (("nvidia-driver" . + "1qnsyzplkxfcc2sj6fcw3ylfp0njvb5z1c0y4v80zzqwqw4il84r") + ("nvidia-settings" . + "18sij736liyhqysvsnqwb6r58pf0zbggxyvyc11psc4ljxg30h8m"))))) + (let ((hashes (assoc-ref %nvidia-source-hashes version))) + (assoc-ref hashes package))) + +(define (nvidia-source-unbundle-libraries version) + #~(begin + (use-modules (guix build utils)) + (for-each delete-file + (find-files "." (string-join + '(;; egl-gbm + "libnvidia-egl-gbm\\.so\\." + ;; egl-wayland + "libnvidia-egl-wayland\\.so\\." + ;; libglvnd + "libEGL\\.so\\." + "libGL\\.so\\." + "libGLESv1_CM\\.so\\." + "libGLESv2\\.so\\." + "libGLX\\.so\\." + "libGLdispatch\\.so\\." + "libOpenGL\\.so\\." + ;; nvidia-settings + "libnvidia-gtk[23]\\.so\\." + ;; opencl-icd-loader + "libOpenCL\\.so\\.") + "|"))))) + +(define* (make-nvidia-source + version hash + #:optional (get-cleanup-snippet nvidia-source-unbundle-libraries)) + "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 + (method (@@ (guix packages) computed-origin-method)) + (file-name (string-append "nvidia-driver-" version "-checkout")) + (sha256 #f) + (snippet (get-cleanup-snippet version)) + (uri + (delay + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils) + (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 (nvidia-source-hash nvidia-version)))) + + +;;; +;;; NVIDIA drivers +;;; + + +(define %nvidia-script-create-device-nodes + (program-file + "create-device-nodes.scm" + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (ice-9 regex) + (rnrs io ports) + (srfi srfi-1) + (guix build utils)) + + (define %nvidia-character-devices + (call-with-input-file "/proc/devices" + (lambda (port) + (filter-map + (lambda (line) + (if (string-contains line "nvidia") + (apply cons (reverse (string-tokenize line))) + #f)) + (string-split (get-string-all port) #\newline))))) + + (define %nvidia-driver-device-minors + (let ((device-minor-regexp (make-regexp "^Device Minor: \t (.*)"))) + (append-map + (lambda (file) + (call-with-input-file file + (lambda (port) + (filter-map + (lambda (line) + (let ((matched (regexp-exec device-minor-regexp line))) + (if matched + (match:substring matched 1) + #f))) + (string-split (get-string-all port) #\newline))))) + (find-files "/proc/driver/nvidia/gpus/" "information$")))) + + (define (create-device-node path name minor) + (let ((major + (or (assoc-ref %nvidia-character-devices name) + (assoc-ref %nvidia-character-devices "nvidia-frontend"))) + (mknod #$(file-append coreutils "/bin/mknod"))) + (system* mknod "-Zm0666" path "c" major minor))) + + (define (main args) + (case (string->symbol (first args)) + ((nvidia_modeset) + (create-device-node "/dev/nvidia-modeset" "nvidia-modeset" "254")) + ((nvidia_uvm) + (begin + (create-device-node "/dev/nvidia-uvm" "nvidia-uvm" "0") + (create-device-node "/dev/nvidia-uvm-tools" "nvidia-uvm" "1"))) + ((nvidia) + (begin + (create-device-node "/dev/nvidiactl" "nvidiactl" "255") + (for-each + (lambda (minor) + (create-device-node + (string-append "/dev/nvidia" minor) "nvidia" minor)) + %nvidia-driver-device-minors))))) + + (main (cdr (command-line))))))) -; Used for closed-source packages -(define nvidia-version "470.86") +;; Adapted from <https://github.com/Frogging-Family/nvidia-all/blob/master/60-nvidia.rules> +(define %nvidia-udev-rules + (mixed-text-file + "90-nvidia.rules" "\ +# Make sure device nodes are present even when the DDX is not started for the Wayland/EGLStream case +KERNEL==\"nvidia\", RUN+=\"" %nvidia-script-create-device-nodes " nvidia\" +KERNEL==\"nvidia_modeset\", RUN+=\"" %nvidia-script-create-device-nodes " nvidia_modeset\" +KERNEL==\"nvidia_uvm\", RUN+=\"" %nvidia-script-create-device-nodes " nvidia_uvm\" -; Used for the open-source kernel module package -(define nversion "515.76") +# Enable runtime PM for NVIDIA VGA/3D controller devices +ACTION==\"bind\", SUBSYSTEM==\"pci\", ATTR{vendor}==\"0x10de\", ATTR{class}==\"0x03[0-9]*\", TEST==\"power/control\", ATTR{power/control}=\"auto\" +# Enable runtime PM for NVIDIA Audio devices +ACTION==\"bind\", SUBSYSTEM==\"pci\", ATTR{vendor}==\"0x10de\", ATTR{class}==\"0x040300\", TEST==\"power/control\", ATTR{power/control}=\"auto\" +# Enable runtime PM for NVIDIA USB xHCI Host Controller devices +ACTION==\"bind\", SUBSYSTEM==\"pci\", ATTR{vendor}==\"0x10de\", ATTR{class}==\"0x0c0330\", TEST==\"power/control\", ATTR{power/control}=\"auto\" +# Enable runtime PM for NVIDIA USB Type-C UCSI devices +ACTION==\"bind\", SUBSYSTEM==\"pci\", ATTR{vendor}==\"0x10de\", ATTR{class}==\"0x0c8000\", TEST==\"power/control\", ATTR{power/control}=\"auto\" + +# Disable runtime PM for NVIDIA VGA/3D controller devices +ACTION==\"unbind\", SUBSYSTEM==\"pci\", ATTR{vendor}==\"0x10de\", ATTR{class}==\"0x03[0-9]*\", TEST==\"power/control\", ATTR{power/control}=\"on\" +# Disable runtime PM for NVIDIA Audio devices +ACTION==\"unbind\", SUBSYSTEM==\"pci\", ATTR{vendor}==\"0x10de\", ATTR{class}==\"0x040300\", TEST==\"power/control\", ATTR{power/control}=\"on\" +# Disable runtime PM for NVIDIA USB xHCI Host Controller devices +ACTION==\"unbind\", SUBSYSTEM==\"pci\", ATTR{vendor}==\"0x10de\", ATTR{class}==\"0x0c0330\", TEST==\"power/control\", ATTR{power/control}=\"on\" +# Disable runtime PM for NVIDIA USB Type-C UCSI devices +ACTION==\"unbind\", SUBSYSTEM==\"pci\", ATTR{vendor}==\"0x10de\", ATTR{class}==\"0x0c8000\", TEST==\"power/control\", ATTR{power/control}=\"on\" +")) (define-public nvidia-driver (package (name "nvidia-driver") (version nvidia-version) - (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")) - (method url-fetch) - (file-name (string-append "nvidia-driver-" version "-checkout")))) + (source nvidia-source) + (build-system copy-build-system) + (arguments + (list #:modules '((guix build copy-build-system) + (guix build utils) + (ice-9 popen) + (ice-9 rdelim) + (ice-9 regex) + (srfi srfi-26)) + #:install-plan + #~`((#$(match (or (%current-target-system) (%current-system)) + ("i686-linux" "32") + ("x86_64-linux" ".") + (_ ".")) + "lib/" #:include-regexp ("^./[^/]+\\.so")) + ("." "share/nvidia/" #:include-regexp ("nvidia-application-profiles")) + ("." "share/egl/egl_external_platform.d/" #:include-regexp ("(gbm|wayland)\\.json")) + ("10_nvidia.json" "share/glvnd/egl_vendor.d/") + ("90-nvidia.rules" "lib/udev/rules.d/") + ("nvidia-drm-outputclass.conf" "share/X11/xorg.conf.d/") + ("nvidia-dbus.conf" "share/dbus-1/system.d/") + ("nvidia.icd" "etc/OpenCL/vendors/") + ("nvidia_icd.json" "share/vulkan/icd.d/") + ("nvidia_layers.json" "share/vulkan/implicit_layer.d/")) + #:phases + #~(modify-phases %standard-phases + (delete 'strip) + (add-after 'unpack 'create-misc-files + (lambda* (#:key inputs #:allow-other-keys) + ;; EGL external platform configuraiton + (substitute* '("10_nvidia_wayland.json" + "15_nvidia_gbm.json") + (("libnvidia-egl-(wayland|gbm)\\.so\\.." all) + (search-input-file inputs (string-append "lib/" all)))) + + ;; EGL vendor ICD configuration + (substitute* "10_nvidia.json" + (("libEGL_nvidia\\.so\\.." all) + (string-append #$output "/lib/" all))) + + ;; OpenCL vendor ICD configuration + (substitute* "nvidia.icd" + (("libnvidia-opencl\\.so\\.." all) + (string-append #$output "/lib/" all))) + + ;; Vulkan ICD & layer configuraiton + (substitute* '("nvidia_icd.json" + "nvidia_layers.json") + (("libGLX_nvidia\\.so\\.." all) + (string-append #$output "/lib/" all))) + + ;; Add udev rules + (symlink #$%nvidia-udev-rules "90-nvidia.rules"))) + (add-after 'install 'add-architecture-to-filename + (lambda _ + (for-each + (lambda (path) + (let* ((out #$output) + (system #$(or (%current-target-system) + (%current-system))) + (dash (string-index system #\-)) + (arch (string-take system dash)) + + (dot (string-index-right path #\.)) + (base (string-take path dot)) + (ext (string-drop path (+ 1 dot)))) + ;; <...>/nvidia.icd -> <...>/nvidia.x86_64.icd + ;; <...>/nvidia_icd.json -> <...>/nvidia_icd.x86_64.json + (rename-file + (string-append out path) + (string-append out base "." arch "." ext)))) + '("/etc/OpenCL/vendors/nvidia.icd" + "/share/egl/egl_external_platform.d/10_nvidia_wayland.json" + "/share/egl/egl_external_platform.d/15_nvidia_gbm.json" + "/share/glvnd/egl_vendor.d/10_nvidia.json" + "/share/vulkan/icd.d/nvidia_icd.json" + "/share/vulkan/implicit_layer.d/nvidia_layers.json")))) + (add-after 'install 'patch-elf + (lambda _ + (let* ((ld.so (string-append #$(this-package-input "glibc") + #$(glibc-dynamic-linker))) + (rpath (string-join + (list (string-append #$output "/lib") + (string-append #$openssl-1.1 "/lib") + (string-append #$(this-package-input "egl-wayland") "/lib") + (string-append (ungexp (this-package-input "gcc") "lib") "/lib") + (string-append #$(this-package-input "glibc") "/lib") + (string-append #$(this-package-input "libdrm") "/lib") + (string-append #$(this-package-input "libglvnd") "/lib") + (string-append #$(this-package-input "libx11") "/lib") + (string-append #$(this-package-input "libxext") "/lib") + (string-append #$(this-package-input "openssl") "/lib") + (string-append #$(this-package-input "wayland") "/lib")) + ":"))) + (define (patch-elf file) + (format #t "Patching ~a ..." file) + (unless (string-contains file ".so") + (invoke "patchelf" "--set-interpreter" ld.so file)) + (invoke "patchelf" "--set-rpath" rpath file) + (display " done\n")) + + (for-each (lambda (file) + (when (elf-file? file) + (patch-elf file))) + (find-files #$output))))) + (add-before 'patch-elf 'install-commands + (lambda _ + (when (string-match + "x86_64-linux" + (or #$(%current-target-system) #$(%current-system))) + (for-each + (lambda (binary) + (let ((bindir (string-append #$output "/bin")) + (manual (string-append binary ".1.gz")) + (mandir (string-append #$output "/share/man/man1"))) + (install-file binary bindir) + (when (file-exists? manual) + (install-file manual mandir)))) + '("nvidia-cuda-mps-control" + "nvidia-cuda-mps-server" + "nvidia-smi"))))) + (add-before 'patch-elf 'relocate-libraries + (lambda _ + (let* ((version #$(package-version this-package)) + (libdir (string-append #$output "/lib")) + (gbmdir (string-append libdir "/gbm")) + (vdpaudir (string-append libdir "/vdpau")) + (xorgmoddir (string-append libdir "/xorg/modules")) + (xorgdrvdir (string-append xorgmoddir "/drivers")) + (xorgextdir (string-append xorgmoddir "/extensions")) + (move-to-dir (lambda (file dir) + (install-file file dir) + (delete-file file)))) + (for-each + (lambda (file) + (mkdir-p gbmdir) + (with-directory-excursion gbmdir + (symlink file "nvidia-drm_gbm.so"))) + (find-files libdir "libnvidia-allocator\\.so\\.")) + + (for-each + (cut move-to-dir <> vdpaudir) + (find-files libdir "libvdpau_nvidia\\.so\\.")) + + (for-each + (cut move-to-dir <> xorgdrvdir) + (find-files libdir "nvidia_drv\\.so$")) + + (for-each + (lambda (file) + (move-to-dir file xorgextdir) + (with-directory-excursion xorgextdir + (symlink (basename file) + "libglxserver_nvidia.so"))) + (find-files libdir "libglxserver_nvidia\\.so\\."))))) + (add-after 'patch-elf 'create-short-name-symlinks + (lambda _ + (define (get-soname file) + (when (elf-file? file) + (let* ((cmd (string-append "patchelf --print-soname " file)) + (port (open-input-pipe cmd)) + (soname (read-line port))) + (close-pipe port) + soname))) + (for-each + (lambda (lib) + (let ((lib-soname (get-soname lib))) + (when (string? lib-soname) + (let* ((soname (string-append + (dirname lib) "/" lib-soname)) + (base (string-append + (regexp-substitute + #f (string-match "(.*)\\.so.*" soname) 1) + ".so")) + (source (basename lib))) + (for-each + (lambda (target) + (unless (file-exists? target) + (format #t "Symlinking ~a -> ~a..." + target source) + (symlink source target) + (display " done\n"))) + (list soname base)))))) + (find-files #$output "\\.so\\."))))))) + (supported-systems '("i686-linux" "x86_64-linux")) + (native-inputs (list patchelf)) + (inputs + (list egl-gbm + egl-wayland + `(,gcc "lib") + glibc + libdrm + libglvnd-for-nvda + libx11 + libxext + openssl + openssl-1.1 + wayland)) + (home-page "https://www.nvidia.com") + (synopsis "Proprietary NVIDIA driver (libraries)") + (description + "This package provides libraries of the proprietary NVIDIA driver. It's +mainly used as a dependency of other packages. For user-facing purpose, use +@code{nvda} instead.") + (license + (license:nonfree + (format #f "file:///share/doc/nvidia-driver-~a/LICENSE" version))))) + +(define-public nvidia-libs + (deprecated-package "nvidia-libs" nvidia-driver)) + + +;;; +;;; NVIDIA frimwares +;;; + + +(define-public nvidia-firmware + (let ((base nvidia-driver)) + (package + (inherit base) + (name "nvidia-firmware") + (arguments + (list #:install-plan + #~'(("firmware" #$(string-append "lib/firmware/nvidia/" + (package-version this-package)))) + #:phases + #~(modify-phases %standard-phases + (delete 'strip)))) + (propagated-inputs '()) + (inputs '()) + (native-inputs '()) + (synopsis "Proprietary NVIDIA driver (GSP firmwares)") + (description + "This package provides firmwares for NVIDIA's GPU System Processor. +Firmware installation can be done with @code{nvidia-service-type}, however +whether GSP mode is enabled by default or not depends on the specific GPU +product. + +To enable GSP mode manually, add @code{\"NVreg_EnableGpuFirmware=1\"} to +@code{kernel-arguments} field of the @code{operating-system} configuration.")))) + + +;;; +;;; NVIDIA kernel modules +;;; + + +(define-public nvidia-module + (package + (name "nvidia-module") + (version nvidia-version) + (source nvidia-source) (build-system linux-module-build-system) (arguments (list #:linux linux-lts - #:tests? #f - #:phases - #~(modify-phases %standard-phases - (replace 'unpack - (lambda* (#:key inputs #:allow-other-keys #:rest r) - (let ((source (assoc-ref inputs "source"))) - (invoke "sh" source "--extract-only") - (chdir #$(format #f "NVIDIA-Linux-x86_64-~a" version))))) - (replace 'build - (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. - (chdir "kernel") - ;; Patch Kbuild - (substitute* "Kbuild" - (("/bin/sh") (string-append #$bash-minimal "/bin/sh"))) - (invoke "make" - "-j" - (string-append "SYSSRC=" - (assoc-ref inputs "linux-module-builder") - "/lib/modules/build") - "CC=gcc"))) - (delete 'strip) - (add-after 'install 'install-copy - (lambda* (#:key inputs native-inputs outputs #:allow-other-keys) - (chdir "..") - (use-modules (ice-9 ftw) - (ice-9 regex) - (ice-9 textual-ports)) - (let* ((libdir (string-append #$output "/lib")) - (bindir (string-append #$output "/bin")) - (etcdir (string-append #$output "/etc"))) - ;; ------------------------------ - ;; Copy .so files - (for-each - (lambda (file) - (format #t "Copying '~a'...~%" file) - (install-file file libdir)) - (scandir "." (lambda (name) - (string-contains name ".so")))) - - (install-file "nvidia_drv.so" (string-append #$output "/lib/xorg/modules/drivers/")) - (install-file (string-append "libglxserver_nvidia.so." - #$(package-version nvidia-driver)) - (string-append #$output "/lib/xorg/modules/extensions/")) - - ;; ICD Loader for OpenCL - (let ((file (string-append etcdir "/OpenCL/vendors/nvidia.icd"))) - (mkdir-p (string-append etcdir "/OpenCL/vendors/")) - (call-with-output-file file - (lambda (port) - (display (string-append #$output "/lib/libnvidia-opencl.so.1") port))) - (chmod file #o555)) - - ;; Add udev rules for nvidia - (let ((rulesdir (string-append #$output "/lib/udev/rules.d/")) - (rules (string-append #$output "/lib/udev/rules.d/90-nvidia.rules")) - (sh (string-append #$bash-minimal "/bin/sh")) - (mknod (string-append #$coreutils "/bin/mknod")) - (cut (string-append #$coreutils "/bin/cut")) - (grep (string-append #$grep "/bin/grep"))) - (mkdir-p rulesdir) - (call-with-output-file rules - (lambda (port) - (put-string port + #:source-directory "kernel" + #:tests? #f + #:make-flags + #~(list (string-append "CC=" #$(cc-for-target))) + #:phases + #~(modify-phases %standard-phases + (delete 'strip) + (add-before 'configure 'fixpath + (lambda* (#:key (source-directory ".") #:allow-other-keys) + (substitute* (string-append source-directory "/Kbuild") + (("/bin/sh") (which "sh"))))) + (replace 'build + (lambda* (#:key (make-flags '()) (parallel-build? #t) + (source-directory ".") + inputs + #:allow-other-keys) + (apply invoke "make" "-C" (canonicalize-path source-directory) + (string-append "SYSSRC=" (search-input-directory + inputs "/lib/modules/build")) + `(,@(if parallel-build? + `("-j" ,(number->string + (parallel-job-count))) + '()) + ,@make-flags))))))) + (home-page "https://www.nvidia.com") + (synopsis "Proprietary NVIDIA driver (kernel modules)") + (description + "This package provides kernel modules of the proprietary NVIDIA driver. +Module setup can be done with @code{nvidia-service-type}, to actually use these +modules, also add @code{modprobe.blacklist=nouveau} to @code{kernel-arguments} +field of the @code{operating-system} configuration. + +If the NVIDIA card is not used for displaying, or on a Wayland environment, +add @code{nvidia_drm.modeset=1} to @code{kernel-arguments} as well.") + (license + (license:nonfree + (format #f "file:///share/doc/nvidia-driver-~a/LICENSE" version))))) + +(define-public nvidia-module-open + (let ((base nvidia-module)) + (package + (inherit base) + (name "nvidia-module-open") + (arguments + (substitute-keyword-arguments (package-arguments base) + ;; NOTE: Kernels compiled with CONFIG_LTO_CLANG_THIN would cause an + ;; error here. See also: + ;; <https://github.com/NVIDIA/open-gpu-kernel-modules/issues/214> + ;; <https://github.com/llvm/llvm-project/issues/55820> + ((#:source-directory _) "kernel-open"))) + (home-page "https://github.com/NVIDIA/open-gpu-kernel-modules") + (synopsis "Open source NVIDIA kernel modules") + (description + "This package provides open source NVIDIA kernel modules, however +proprietary firmware and libraries are still necessary, and these modules +require GPU System Processor to be present (Turing or later architectures) and +enabled (see also the description of @code{nvidia-firmware} package). + +Module setup can be done with @code{nvidia-service-type} (with @code{module} +field of @code{nvidia-configuration} set to @code{nvidia-module-open}), to +actually use these modules, also add @code{modprobe.blacklist=nouveau} to +@code{kernel-arguments} field of the @code{operating-system} configuration. + +If the NVIDIA card is not used for displaying, or on a Wayland environment, +add @code{nvidia_drm.modeset=1} to @code{kernel-arguments} as well.") + (license license-gnu:gpl2)))) + + +;;; +;;; ‘nvidia-settings’ packages +;;; + + +(define-public nvidia-settings + (package + (name "nvidia-settings") + (version nvidia-version) + (source (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 (nvidia-source-hash version name))))) + (build-system gnu-build-system) + (arguments + (list #:tests? #f ;no test suite + #:make-flags + #~(list "NV_USE_BUNDLED_LIBJANSSON=0" + (string-append "PREFIX=" #$output) + (string-append "CC=" #$(cc-for-target))) + #:phases + #~(modify-phases %standard-phases + (delete 'configure) + (add-after 'unpack 'fix-application-profile-path + (lambda* (#:key inputs #:allow-other-keys) + (substitute* "src/gtk+-2.x/ctkappprofile.c" + (("/usr") "/run/booted-system/profile")))) + (add-after 'install 'install-desktop-file + (lambda _ + (substitute* "doc/nvidia-settings.desktop" + (("^Exec=.*") "Exec=nvidia-settings\n") + (("__NVIDIA_SETTINGS_DESKTOP_CATEGORIES__") "Settings")) + (install-file "doc/nvidia-settings.desktop" (string-append - "KERNEL==\"nvidia\", " - "RUN+=\"" sh " -c '" mknod " -m 666 /dev/nvidiactl c $$(" grep " nvidia-frontend /proc/devices | " cut " -d \\ -f 1) 255'\"" "\n" - "KERNEL==\"nvidia_modeset\", " - "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\", " - "RUN+=\"" sh " -c '" mknod " -m 666 /dev/nvidia0 c $$(" grep " nvidia-frontend /proc/devices | " cut " -d \\ -f 1) 0'\"" "\n" - "KERNEL==\"nvidia_uvm\", " - "RUN+=\"" sh " -c '" mknod " -m 666 /dev/nvidia-uvm c $$(" grep " nvidia-uvm /proc/devices | " cut " -d \\ -f 1) 0'\"" "\n" - "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" ))))) - - ;; ------------------------------ - ;; Add a file to load nvidia drivers - (mkdir-p bindir) - (let ((file (string-append bindir "/nvidia-insmod")) - (moddir (string-append "/lib/modules/" (utsname:release (uname)) "-gnu/extra"))) - (call-with-output-file file - (lambda (port) - (put-string port (string-append "#!" (assoc-ref inputs "bash-minimal") "/bin/sh" "\n" - "modprobe ipmi_devintf" "\n" - "insmod " #$output moddir "/nvidia.ko" "\n" - "insmod " #$output moddir "/nvidia-modeset.ko" "\n" - "insmod " #$output moddir "/nvidia-uvm.ko" "\n" - "insmod " #$output moddir "/nvidia-drm.ko" "\n")))) - (chmod file #o555)) - (let ((file (string-append bindir "/nvidia-rmmod"))) - (call-with-output-file file - (lambda (port) - (put-string port (string-append "#!" #$bash-minimal "/bin/sh" "\n" - "rmmod " "nvidia-drm" "\n" - "rmmod " "nvidia-uvm" "\n" - "rmmod " "nvidia-modeset" "\n" - "rmmod " "nvidia" "\n" - "rmmod " "ipmi_devintf" "\n")))) - (chmod file #o555)) - - ;; ------------------------------ - ;; nvidia-smi - - (install-file "nvidia-smi" bindir) - - ;; ------------------------------ - ;; patchelf - (let* ((ld.so (string-append #$glibc #$(glibc-dynamic-linker))) - - (rpath (string-join - (list "$ORIGIN" - (string-append #$output "/lib") - (string-append #$glibc "/lib") - (string-append #$libx11 "/lib") - (string-append #$libxext "/lib") - (string-append #$pango "/lib") - (string-append #$gtk+ "/lib") - (string-append #$gtk+-2 "/lib") - (string-append #$atk "/lib") - (string-append #$glib "/lib") - (string-append #$cairo "/lib") - (string-append #$gdk-pixbuf "/lib") - (string-append #$wayland "/lib") - (string-append #$gcc:lib "/lib")) - ":"))) - (define (patch-elf file) - (format #t "Patching ~a ...~%" file) - (unless (string-contains file ".so") - (invoke "patchelf" "--set-interpreter" ld.so file)) - (invoke "patchelf" "--set-rpath" rpath file)) - (for-each (lambda (file) - (when (elf-file? file) - (patch-elf file))) - (find-files #$output ".*\\.so")) - (patch-elf (string-append bindir "/" "nvidia-smi"))) - - ;; ------------------------------ - ;; Create short name symbolic links - (for-each (lambda (file) - (let* ((short (regexp-substitute - #f - (string-match "([^/]*\\.so).*" file) - 1)) - (major (cond - ((or (string=? short "libGLX.so") - (string=? short "libGLX_nvidia.so") - (string=? short "libEGL_nvidia.so")) "0") - ((string=? short "libGLESv2.so") "2") - (else "1"))) - (mid (string-append short "." major)) - (short-file (string-append libdir "/" short)) - (mid-file (string-append libdir "/" mid))) - ;; FIXME the same name, print out warning at least - ;; [X] libEGL.so.1.1.0 - ;; [ ] libEGL.so.435.21 - (when (not (file-exists? short-file)) - (format #t "Linking ~a to ~a ...~%" short file) - (symlink (basename file) short-file)) - (when (not (file-exists? mid-file)) - (format #t "Linking ~a to ~a ...~%" mid file) - (symlink (basename file) mid-file)))) - (find-files libdir "\\.so\\.")) - (symlink (string-append "libglxserver_nvidia.so." - #$(package-version nvidia-driver)) - (string-append #$output "/lib/xorg/modules/extensions/" "libglxserver_nvidia.so")))))))) - (supported-systems '("x86_64-linux")) - (native-inputs - (list - patchelf - perl - python-2 - which - xz)) - (inputs + #$output "/share/applications")) + (install-file "doc/nvidia-settings.png" + (string-append + #$output "/share/icons/hicolor/128x128/apps")))) + (add-after 'install 'wrap-program + (lambda* (#:key outputs #:allow-other-keys) + (let ((out (assoc-ref outputs "out"))) + (wrap-program (string-append out "/bin/nvidia-settings") + `("LD_LIBRARY_PATH" ":" prefix + (,(string-append out "/lib/")))))))))) + (native-inputs (list m4 + pkg-config)) + (inputs (list bash-minimal + dbus + glu + gtk+ + gtk+-2 + jansson + libvdpau + libx11 + libxext + libxrandr + libxv + libxxf86vm)) + (synopsis "Nvidia driver control panel") + (description + "This package provides Nvidia driver control panel for monitor +configuration, creating application profiles, gpu monitoring and more.") + (home-page "https://github.com/NVIDIA/nvidia-settings") + (license license-gnu:gpl2))) + + +;;; +;;; ‘nvda’ packages +;;; + + +(define-public libglvnd-for-nvda + (hidden-package + (package + (inherit libglvnd) + (arguments + (substitute-keyword-arguments (package-arguments libglvnd) + ((#:configure-flags flags #~'()) + #~(cons* "-Dc_link_args=-Wl,-rpath=$ORIGIN" #$flags)) + ((#:phases phases #~%standard-phases) + #~(modify-phases #$phases + (delete 'shrink-runpath)))))))) + +(define-public mesa-for-nvda + (hidden-package + (package + (inherit mesa) + (propagated-inputs + (modify-inputs (package-propagated-inputs mesa) + (prepend libglvnd-for-nvda))) + (arguments + (substitute-keyword-arguments (package-arguments mesa) + ((#:configure-flags flags #~'()) + #~(cons* "-Dglvnd=true" #$flags)) + ((#:phases phases #~%standard-phases) + #~(modify-phases #$phases + (add-after 'install 'fix-egl-vendor-icd + (lambda _ + (substitute* (string-append + #$output "/share/glvnd/egl_vendor.d/50_mesa.json") + (("libEGL_mesa\\.so\\.." all) + (string-append #$output "/lib/" all))))) + (add-after 'set-layer-path-in-manifests 'add-architecture-to-filename + (lambda _ + (for-each + (lambda (path) + (let* ((out #$output) + (system #$(or (%current-target-system) + (%current-system))) + (dash (string-index system #\-)) + (arch (string-take system dash)) + + (dot (string-index-right path #\.)) + (base (string-take path dot)) + (ext (string-drop path (+ 1 dot)))) + ;; <...>/50_mesa.json -> <...>/50_mesa.x86_64.json + (rename-file + (string-append out path) + (string-append out base "." arch "." ext)))) + '("/share/glvnd/egl_vendor.d/50_mesa.json" + "/share/vulkan/explicit_layer.d/VkLayer_MESA_overlay.json" + "/share/vulkan/implicit_layer.d/VkLayer_MESA_device_select.json"))))))))))) + +;; nvda is used as a name because it has the same length as mesa which is +;; required for grafting +(define-public nvda + (package + (inherit nvidia-driver) + (name "nvda") + (version (string-pad-right + (package-version nvidia-driver) + (string-length (package-version mesa-for-nvda)) + #\0)) + (source #f) + (build-system trivial-build-system) + (arguments + (list #:modules '((guix build union)) + #:builder + #~(begin + (use-modules (guix build union)) + (union-build + #$output + '#$(list (this-package-input "libglvnd") + (this-package-input "mesa") + (this-package-input "nvidia-driver")))))) + (native-search-paths (list - atk - bash-minimal - cairo - coreutils - `(,gcc "lib") - gdk-pixbuf - glib - grep - gtk+ - gtk+-2 - kmod - glibc - libx11 - libxext - linux-lts - pango - wayland)) - (home-page "https://www.nvidia.com") - (synopsis "Proprietary Nvidia driver") - (description "This is the evil Nvidia driver. Don't forget to add -nvidia-driver to the udev-rules in your config.scm: -@code{(simple-service 'custom-udev-rules udev-service-type (list nvidia-driver))} -Further xorg should be configured by adding: -@code{(modules (cons* nvidia-driver %default-xorg-modules)) -(drivers '(\"nvidia\"))} to @code{xorg-configuration}.") - (license (license:nonfree (format #f "file:///share/doc/nvidia-driver-~a/LICENSE" version))))) + ;; https://github.com/NVIDIA/egl-wayland/issues/39 + (search-path-specification + (variable "__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS") + (files '("share/egl/egl_external_platform.d"))) + ;; https://gitlab.freedesktop.org/glvnd/libglvnd/-/blob/master/src/EGL/icd_enumeration.md + (search-path-specification + (variable "__EGL_VENDOR_LIBRARY_DIRS") + (files '("share/glvnd/egl_vendor.d"))) + ;; See also: ‘src/gbm/main/backend.c’ in mesa source. + (search-path-specification + (variable "GBM_BACKENDS_PATH") + (files '("lib/gbm"))) + (search-path-specification + (variable "VDPAU_DRIVER_PATH") + (files '("lib/vdpau")) + (separator #f)) + ;; https://github.com/KhronosGroup/Vulkan-Loader/blob/main/docs/LoaderLayerInterface.md + (search-path-specification + (variable "XDG_DATA_DIRS") + (files '("share"))))) + (synopsis "Nonguix's user-facing NVIDIA driver package") + (description + "This package provides a drop-in replacement for @code{mesa} and is +intended to be installed by @code{nvidia-service-type}. + +To actually use the NVIDIA card, replacement must be applied for individual +packages, this can be done either by rewriting inputs with +@code{--with-input=mesa=nvda} or grafting with @code{--with-graft=mesa=nvda}. +For a programmatical way, the procedure @code{replace-mesa} can be used. + +Additionally, if the NVIDIA card is not used for displaying, environment +variables @code{__GLX_VENDOR_LIBRARY_NAME=nvidia} and +@code{__NV_PRIME_RENDER_OFFLOAD=1} may be set.") + (native-inputs '()) + (propagated-inputs + (append + (package-propagated-inputs mesa-for-nvda) + (package-propagated-inputs nvidia-driver))) + (inputs (list mesa-for-nvda nvidia-driver)) + (outputs '("out")))) + +(define mesa/fake + (package + (inherit mesa) + (replacement nvda))) + +(define-public replace-mesa + (package-input-rewriting `((,mesa . ,mesa/fake)))) + + +;;; +;;; Other packages +;;; + + +(define-public gpustat + (package + (name "gpustat") + (version "1.0.0") + (source (origin + (method url-fetch) + (uri (pypi-uri "gpustat" version)) + (sha256 + (base32 + "1wg3yikkqdrcxp5xscyb9rxifgfwv7qh73xv4airab63b3w8y7jq")))) + (build-system python-build-system) + (arguments + '(#:tests? #f)) + (propagated-inputs (list python-blessed python-nvidia-ml-py python-psutil + python-six)) + (native-inputs (list python-mock python-pytest python-pytest-runner)) + (home-page "https://github.com/wookayin/gpustat") + (synopsis "Utility to monitor NVIDIA GPU status and usage") + (description + "This package provides an utility to monitor NVIDIA GPU status +and usage.") + (license license-gnu:expat))) (define-public nvidia-exec (package @@ -310,18 +829,18 @@ Further xorg should be configured by adding: (add-after 'install 'wrap-nvx (lambda* (#:key inputs outputs #:allow-other-keys) (wrap-program (string-append #$output "/bin/nvx") - `("PATH" ":" prefix - ,(fold (lambda (input paths) - (let* ((in (assoc-ref - inputs input)) - (bin (string-append - in "/bin"))) - (append (filter - file-exists? - (list bin)) - paths))) - '() - '("jq" "lshw" "lsof"))))))))) + `("PATH" ":" prefix + ,(fold (lambda (input paths) + (let* ((in (assoc-ref + inputs input)) + (bin (string-append + in "/bin"))) + (append (filter + file-exists? + (list bin)) + paths))) + '() + '("jq" "lshw" "lsof"))))))))) (inputs (list bash-minimal jq lshw lsof)) (home-page "https://github.com/pedro00dk/nvidia-exec") (synopsis "GPU switching without login out for Nvidia Optimus laptops") @@ -330,6 +849,34 @@ Further xorg should be configured by adding: laptops.") (license license-gnu:gpl3+))) +(define-public nvidia-htop + (package + (name "nvidia-htop") + (version "1.0.5") + (source (origin + (method url-fetch) + (uri (pypi-uri "nvidia-htop" version)) + (sha256 + (base32 + "0lv9cpccpkbg0d577irm1lp9rx6pacyk2pk9v41k9s9hyl4b7hvx")))) + (build-system python-build-system) + (arguments + (list #:phases #~(modify-phases %standard-phases + (add-after 'unpack 'fix-libnvidia + (lambda _ + (substitute* "nvidia-htop.py" + (("nvidia-smi") + (string-append #$(this-package-input + "nvidia-driver") + "/bin/nvidia-smi")))))))) + (inputs (list nvidia-driver)) + (propagated-inputs (list python-termcolor)) + (home-page "https://github.com/peci1/nvidia-htop") + (synopsis "Tool to enrich the output of nvidia-smi") + (description "This package provides tool for enriching the output of +nvidia-smi.") + (license license-gnu:bsd-3))) + (define-public nvidia-nvml (package (name "nvidia-nvml") @@ -368,257 +915,98 @@ simultaneous NVML calls from multiple threads.") ;; Doesn't have any specific LICENSE file, but see COPYRIGHT.txt for details. (license (license:nonfree "file://COPYRIGHT.txt")))) -(define-public nvidia-libs - (package - (name "nvidia-libs") - (version nvidia-version) - (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")) - (method url-fetch) - (file-name (string-append "nvidia-driver-" version "-checkout")))) - (build-system copy-build-system) - (arguments - `(#:phases - (modify-phases %standard-phases - (replace 'unpack - (lambda* (#:key inputs #:allow-other-keys #:rest r) - (let ((source (assoc-ref inputs "source"))) - (invoke "sh" source "--extract-only") - (chdir ,(format #f "NVIDIA-Linux-x86_64-~a" version)) - #t))) - (delete 'build) - (delete 'check) - (add-after 'install 'patch-symlink - (lambda* (#:key inputs native-inputs outputs #:allow-other-keys) - (use-modules (ice-9 ftw) - (ice-9 regex) - (ice-9 textual-ports)) - (let* ((out (assoc-ref outputs "out")) - (libdir (string-append out "/lib")) - (bindir (string-append out "/bin")) - (etcdir (string-append out "/etc"))) - ;; ------------------------------ - ;; patchelf - (let* ((libc (assoc-ref inputs "libc")) - (ld.so (string-append libc ,(glibc-dynamic-linker))) - - (out (assoc-ref outputs "out")) - (rpath (string-join - (list "$ORIGIN" - (string-append out "/lib") - (string-append libc "/lib") - (string-append (assoc-ref inputs "atk") "/lib") - (string-append (assoc-ref inputs "cairo") "/lib") - (string-append (assoc-ref inputs "gcc:lib") "/lib") - (string-append (assoc-ref inputs "gdk-pixbuf") "/lib") - (string-append (assoc-ref inputs "glib") "/lib") - (string-append (assoc-ref inputs "gtk+") "/lib") - (string-append (assoc-ref inputs "gtk2") "/lib") - (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 "wayland") "/lib")) - ":"))) - (define (patch-elf file) - (format #t "Patching ~a ...~%" file) - (unless (string-contains file ".so") - (invoke "patchelf" "--set-interpreter" ld.so file)) - (invoke "patchelf" "--set-rpath" rpath file)) - (for-each (lambda (file) - (when (elf-file? file) - (patch-elf file))) - (find-files out ".*\\.so"))) - - ;; ------------------------------ - ;; Create short name symbolic links - (for-each (lambda (file) - (let* ((short (regexp-substitute - #f - - (string-match "([^/]*\\.so).*" file) - 1)) - (major (cond - ((or (string=? short "libGLX.so") - (string=? short "libGLX_nvidia.so") - (string=? short "libEGL_nvidia.so")) "0") - ((string=? short "libGLESv2.so") "2") - (else "1"))) - (mid (string-append short "." major)) - (short-file (string-append libdir "/" short)) - (mid-file (string-append libdir "/" mid))) - ;; FIXME the same name, print out warning at least - ;; [X] libEGL.so.1.1.0 - ;; [ ] libEGL.so.435.21 - (when (not (file-exists? short-file)) - (format #t "Linking ~a to ~a ...~%" short file) - (symlink (basename file) short-file)) - (when (not (file-exists? mid-file)) - (format #t "Linking ~a to ~a ...~%" mid file) - (symlink (basename file) mid-file)))) - (find-files libdir "\\.so\\.")) - #t)))) - #:install-plan - ,@(match (%current-system) - ("x86_64-linux" '(`(("." "lib" #:include-regexp ("^./[^/]+\\.so"))))) - ("i686-linux" '(`(("32" "lib" #:include-regexp ("^./[^/]+\\.so"))))) - (_ '())))) - (supported-systems '("i686-linux" "x86_64-linux")) - (native-inputs - `(("patchelf" ,patchelf) - ("perl" ,perl) - ("python" ,python-2) - ("which" ,which) - ("xz" ,xz))) - (inputs - `(("atk" ,atk) - ("cairo" ,cairo) - ("gcc:lib" ,gcc "lib") - ("gdk-pixbuf" ,gdk-pixbuf) - ("glib" ,glib) - ("gtk+" ,gtk+) - ("gtk2" ,gtk+-2) - ("libc" ,glibc) - ("libx11" ,libx11) - ("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.") - (license (license:nonfree (format #f "file:///share/doc/nvidia-driver-~a/LICENSE" version))))) - -(define-public nvidia-module +(define-public nvidia-system-monitor (package - (name "nvidia-module") - (version nversion) + (name "nvidia-system-monitor") + (version "1.5") (source (origin (method git-fetch) (uri (git-reference - (url "https://github.com/NVIDIA/open-gpu-kernel-modules") - (commit nversion))) + (url "https://github.com/congard/nvidia-system-monitor-qt") + (commit (string-append "v" version)))) (file-name (git-file-name name version)) (sha256 (base32 - "1mkibm0i943ljcy921i63jzc0db6r4pm1ycmwbka9kddcviyb3gk")))) - (build-system linux-module-build-system) + "0aghdqljvjmc02g9jpc7sb3yhha738ywny51riska56hkxd3jg2l")))) + (build-system cmake-build-system) (arguments - (list #:linux linux - #:source-directory "kernel-open" - #:tests? #f - #:make-flags - #~(list (string-append "CC=" #$(cc-for-target)) - (string-append "SYSSRC=" (assoc-ref %build-inputs - "linux-module-builder") - "/lib/modules/build")) - #:phases - #~(modify-phases %standard-phases - (add-after 'unpack 'fixpath - (lambda* (#:key inputs outputs #:allow-other-keys) - (substitute* "kernel-open/Kbuild" - (("/bin/sh") (string-append #$bash-minimal "/bin/sh"))))) - (replace 'build - (lambda* (#:key make-flags outputs #:allow-other-keys) - (apply invoke - `("make" "-j" - ,@make-flags "modules"))))))) - (inputs (list bash-minimal)) - (home-page "https://github.com/NVIDIA/open-gpu-kernel-modules") - (synopsis "Nvidia kernel module") + (list #:tests? #f + #:phases #~(modify-phases %standard-phases + (add-after 'unpack 'fix-nvidia-smi + (lambda _ + (let ((nvidia-smi (string-append #$(this-package-input + "nvidia-driver") + "/bin/nvidia-smi"))) + (substitute* "src/core/InfoProvider.cpp" + (("nvidia-smi") + nvidia-smi)) + (substitute* "src/main.cpp" + (("which nvidia-smi") + (string-append "which " nvidia-smi)) + (("exec..nvidia-smi") + (string-append "exec(\"" nvidia-smi)))))) + (replace 'install + (lambda* (#:key outputs #:allow-other-keys) + (let ((bin (string-append #$output "/bin"))) + (mkdir-p bin) + (install-file "qnvsm" bin))))))) + (inputs (list qtbase-5 qtdeclarative-5 nvidia-driver)) + (home-page "https://github.com/congard/nvidia-system-monitor-qt") + (synopsis "Task manager for Nvidia graphics cards") (description - "This package provides Nvidia open-gpu-kernel-modules. However, -they are only for the latest GPU architectures Turing and Ampere. Also they -still require firmware file @code{gsp.bin} to be loaded as well as closed -source userspace tools from the corresponding driver release.") - (license license-gnu:gpl2))) + "This package provides a task manager for Nvidia graphics cards.") + (license license-gnu:expat))) -(define-public nvidia-settings +(define-public python-nvidia-ml-py (package - (name "nvidia-settings") - (version nvidia-version) + (name "python-nvidia-ml-py") + (version "11.495.46") (source (origin - (method git-fetch) - (uri (git-reference - (url "https://github.com/NVIDIA/nvidia-settings") - (commit version))) - (file-name (git-file-name name version)) + (method url-fetch) + (uri (pypi-uri "nvidia-ml-py" version)) (sha256 (base32 - "1lnj5hwmfkzs664fxlhljqy323394s1i7qzlpsjyrpm07sa93bky")))) - (build-system gnu-build-system) + "09cnb7xasd7brby52j70y7fqsfm9n6gvgqf769v0cmj74ypy2s4g")))) + (build-system python-build-system) (arguments - (list #:tests? #f ;no test suite - #:make-flags - #~(list (string-append "PREFIX=" #$output) - (string-append "CC=" #$(cc-for-target))) - #:phases - #~(modify-phases %standard-phases - (delete 'configure) - (add-after 'install 'wrap-program - (lambda* (#:key outputs #:allow-other-keys) - (let ((out (assoc-ref outputs "out"))) - (wrap-program (string-append out "/bin/nvidia-settings") - `("LD_LIBRARY_PATH" ":" prefix - (,(string-append out "/lib/")))))))))) - (native-inputs (list m4 - pkg-config)) - (inputs (list bash-minimal - dbus - glu - gtk+ - gtk+-2 - libvdpau - libx11 - libxext - libxrandr - libxv - libxxf86vm)) - (synopsis "Nvidia driver control panel") - (description - "This package provides Nvidia driver control panel for monitor -configuration, creating application profiles, gpu monitoring and more.") - (home-page "https://github.com/NVIDIA/nvidia-settings") - (license license-gnu:gpl2))) + (list #:phases #~(modify-phases %standard-phases + (add-after 'unpack 'fix-libnvidia + (lambda _ + (substitute* "pynvml.py" + (("libnvidia-ml.so.1") + (string-append #$(this-package-input + "nvidia-driver") + "/lib/libnvidia-ml.so.1")))))))) + (inputs (list nvidia-driver)) + (home-page "https://forums.developer.nvidia.com") + (synopsis "Python Bindings for the NVIDIA Management Library") + (description "This package provides official Python Bindings for the NVIDIA +Management Library") + (license license-gnu:bsd-3))) -;; nvda is used as a name because it has the same length as mesa which is -;; required for grafting -(define-public nvda +(define-public python-py3nvml (package - (inherit nvidia-libs) - (name "nvda") - (source #f) - (build-system trivial-build-system) + (name "python-py3nvml") + (version "0.2.7") + (source (origin + (method url-fetch) + (uri (pypi-uri "py3nvml" version)) + (sha256 + (base32 + "0wxxky9amy38q7qjsdmmznk1kqdzwd680ps64i76cvlab421vvh9")))) + (build-system python-build-system) (arguments - (list #:modules '((guix build union)) - #:builder #~(begin - (use-modules (guix build union) - (srfi srfi-1) - (ice-9 regex)) - (union-build (assoc-ref %outputs "out") - (list #$mesa #$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)))))) - (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.") - (inputs - (list mesa - nvidia-libs)) - (outputs '("out")))) - -(define mesa/fake - (package - (inherit mesa) - (replacement nvda))) - -(define-public replace-mesa - (package-input-rewriting `((,mesa . ,mesa/fake)))) + (list #:phases #~(modify-phases %standard-phases + (add-after 'unpack 'fix-libnvidia + (lambda _ + (substitute* "py3nvml/py3nvml.py" + (("libnvidia-ml.so.1") + (string-append #$(this-package-input + "nvidia-driver") + "/lib/libnvidia-ml.so.1")))))))) + (propagated-inputs (list nvidia-driver python-xmltodict)) + (home-page "https://github.com/fbcotter/py3nvml") + (synopsis "Unoffcial Python 3 Bindings for the NVIDIA Management Library") + (description "This package provides unofficial Python 3 Bindings for the +NVIDIA Management Library") + (license license-gnu:bsd-3))) |