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))
|
|
|
|
(nvidia-smi (file-append nvidia-driver "/bin/nvidia-smi"))
|
|
|
|
(rmmod (file-append kmod "/bin/rmmod")))
|
|
|
|
(list (shepherd-service
|
|
|
|
(documentation "Prepare system environment for NVIDIA driver.")
|
|
|
|
(provision '(nvidia))
|
|
|
|
(requirement '(udev user-processes))
|
|
|
|
(start
|
|
|
|
#~(lambda _
|
|
|
|
(when (file-exists? #$nvidia-smi)
|
|
|
|
(system* #$nvidia-smi))))
|
|
|
|
(stop
|
|
|
|
#~(lambda _
|
|
|
|
(system* #$rmmod "nvidia_uvm")))))))
|
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-01-07 14:13:00 +01:00
|
|
|
(compose list nvidia-configuration-module))
|
2022-10-01 09:08:38 +02:00
|
|
|
(service-extension kernel-module-loader-service-type
|
2024-01-07 14:13:00 +01:00
|
|
|
(const '("nvidia_uvm")))))
|
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.")))
|