services: nvidia: Only invoke commands when NVIDIA driver is in use.

* nongnu/services/nvidia.scm (nvidia-service-type): Don't extend
kernel-module-loader-service-type, move this part to…
(nvidia-shepherd-service)[start]: …here.
Check driver and command availablity.
[stop]: Likewise.
[modules]: Add (guix build utils) for ‘invoke/quiet’.
Add (rnrs io ports) for ‘get-line’.

Signed-off-by: John Kehayias <john.kehayias@protonmail.com>
This commit is contained in:
Hilton Chain 2024-02-04 15:08:37 +08:00 committed by John Kehayias
parent 97925d2091
commit 8a56ebb666
No known key found for this signature in database
GPG key ID: 499097AE5EA815D9

View file

@ -34,10 +34,17 @@
(provision '(nvidia))
(requirement '(udev))
(one-shot? #t)
(modules '(((guix build utils) #:select (invoke/quiet))
((rnrs io ports) #:select (get-line))))
(start
#~(lambda _
(when (file-exists? #$nvidia-smi)
(system* #$nvidia-smi))))))))
(when (file-exists? "/proc/driver/nvidia")
(let ((modprobe (call-with-input-file
"/proc/sys/kernel/modprobe" get-line)))
(false-if-exception
(begin
(invoke/quiet modprobe "--" "nvidia_uvm")
(invoke/quiet #$nvidia-smi)))))))))))
(define nvidia-service-type
(service-type
@ -52,8 +59,6 @@
(service-extension firmware-service-type
(compose list nvidia-configuration-firmware))
(service-extension linux-loadable-module-service-type
(compose list nvidia-configuration-module))
(service-extension kernel-module-loader-service-type
(const '("nvidia_uvm")))))
(compose list nvidia-configuration-module))))
(default-value (nvidia-configuration))
(description "Prepare system environment for NVIDIA driver.")))