nongnu: nvidia-driver: Simplify udev rules creation.

* nongnu/packages/nvidia.scm (nvidia-driver)[arguments]<#:phases>: Simplify udev rules creation.

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

View file

@ -135,26 +135,20 @@
;; 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 (search-input-file inputs "/bin/sh"))
(mknod (search-input-file inputs "/bin/mknod"))
(cut (search-input-file inputs "/bin/cut"))
(grep (search-input-file inputs "/bin/grep")))
(rules (string-append #$output "/lib/udev/rules.d/90-nvidia.rules")))
(mkdir-p rulesdir)
(call-with-output-file rules
(lambda (port)
(put-string port
(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" )))))
(put-string port (format #f "~
KERNEL==\"nvidia\", RUN+=\"@sh@ -c '@mknod@ -m 666 /dev/nvidiactl c $$(@grep@ nvidia-frontend /proc/devices | @cut@ -d \\ -f 1) 255'\"
KERNEL==\"nvidia_modeset\", RUN+=\"@sh@ -c '@mknod@ -m 666 /dev/nvidia-modeset c $$(@grep@ nvidia-frontend /proc/devices | @cut@ -d \\ -f 1) 254'\"
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'\"
KERNEL==\"nvidia_uvm\", RUN+=\"@sh@ -c '@mknod@ -m 666 /dev/nvidia-uvm c $$(@grep@ nvidia-uvm /proc/devices | @cut@ -d \\ -f 1) 0'\"
KERNEL==\"nvidia_uvm\", RUN+=\"@sh@ -c '@mknod@ -m 666 /dev/nvidia-uvm-tools c $$(@grep@ nvidia-uvm /proc/devices | @cut@ -d \\ -f 1) 0'\"
"))))
(substitute* rules
(("@\\<(sh|grep|mknod|cut)\\>@" all cmd)
(search-input-file inputs (string-append "/bin/" cmd)))))
;; ------------------------------
;; Add a file to load nvidia drivers