2022-12-19 17:17:39 +01:00
|
|
|
;;; SPDX-License-Identifier: GPL-3.0-or-later
|
2024-01-07 14:24:14 +01:00
|
|
|
;;; Copyright © 2022, 2024 Hilton Chain <hako@ultrarare.space>
|
2022-10-01 09:08:38 +02:00
|
|
|
|
|
|
|
(define-module (nongnu services nvidia)
|
2024-01-07 14:13:00 +01:00
|
|
|
#:use-module (guix gexp)
|
|
|
|
#:use-module (guix records)
|
2022-10-01 09:08:38 +02:00
|
|
|
#:use-module (gnu packages)
|
|
|
|
#:use-module (gnu packages linux)
|
|
|
|
#:use-module (gnu services)
|
|
|
|
#:use-module (gnu services base)
|
|
|
|
#:use-module (gnu services linux)
|
|
|
|
#:use-module (gnu services shepherd)
|
|
|
|
#:use-module (nongnu packages nvidia)
|
|
|
|
#:export (nvidia-configuration
|
|
|
|
nvidia-configuration?
|
|
|
|
nvidia-configuration-record?
|
|
|
|
nvidia-service-type))
|
|
|
|
|
|
|
|
(define-record-type* <nvidia-configuration>
|
|
|
|
nvidia-configuration make-nvidia-configuration
|
|
|
|
nvidia-configuration?
|
2024-01-07 14:13:00 +01:00
|
|
|
(driver nvidia-configuration-driver
|
|
|
|
(default nvda)) ; file-like
|
|
|
|
(firmware nvidia-configuration-firmware
|
|
|
|
(default nvidia-firmware)) ; file-like
|
|
|
|
(module nvidia-configuration-module
|
|
|
|
(default nvidia-module))) ; file-like
|
2022-10-01 09:08:38 +02:00
|
|
|
|
|
|
|
(define (nvidia-shepherd-service config)
|
2024-01-07 14:24:14 +01:00
|
|
|
(let ((nvidia-driver (nvidia-configuration-driver config))
|
2024-02-25 07:19:54 +01:00
|
|
|
(nvidia-smi (file-append nvidia-driver "/bin/nvidia-smi")))
|
2024-01-07 14:24:14 +01:00
|
|
|
(list (shepherd-service
|
|
|
|
(documentation "Prepare system environment for NVIDIA driver.")
|
|
|
|
(provision '(nvidia))
|
2024-02-25 07:19:54 +01:00
|
|
|
(requirement '(udev))
|
|
|
|
(one-shot? #t)
|
2024-02-04 08:08:37 +01:00
|
|
|
(modules '(((guix build utils) #:select (invoke/quiet))
|
|
|
|
((rnrs io ports) #:select (get-line))))
|
2024-01-07 14:24:14 +01:00
|
|
|
(start
|
|
|
|
#~(lambda _
|
2024-02-04 08:08:37 +01:00
|
|
|
(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)))))))))))
|
2022-10-01 09:08:38 +02:00
|
|
|
|
|
|
|
(define nvidia-service-type
|
|
|
|
(service-type
|
|
|
|
(name 'nvidia)
|
|
|
|
(extensions
|
|
|
|
(list (service-extension shepherd-root-service-type
|
|
|
|
nvidia-shepherd-service)
|
2024-01-07 14:13:00 +01:00
|
|
|
(service-extension profile-service-type
|
|
|
|
(compose list nvidia-configuration-driver))
|
2022-10-01 09:08:38 +02:00
|
|
|
(service-extension udev-service-type
|
2024-01-07 14:13:00 +01:00
|
|
|
(compose list nvidia-configuration-driver))
|
2022-10-01 09:08:38 +02:00
|
|
|
(service-extension firmware-service-type
|
2024-01-07 14:13:00 +01:00
|
|
|
(compose list nvidia-configuration-firmware))
|
2022-10-01 09:08:38 +02:00
|
|
|
(service-extension linux-loadable-module-service-type
|
2024-02-04 08:08:37 +01:00
|
|
|
(compose list nvidia-configuration-module))))
|
2022-10-01 09:08:38 +02:00
|
|
|
(default-value (nvidia-configuration))
|
2024-01-07 14:13:00 +01:00
|
|
|
(description "Prepare system environment for NVIDIA driver.")))
|