services: linux: Minor improvements for thinkfan-service

pull/1/head
anemofilia 2023-11-24 01:35:17 -03:00 committed by Luis Guilherme Coelho
parent b5daac8464
commit 04c1389930
No known key found for this signature in database
GPG Key ID: 1F2E76ACE3F531C8
1 changed files with 38 additions and 29 deletions

View File

@ -1,57 +1,66 @@
(define-module (radix services linux) (define-module (radix services linux)
#:use-module (gnu)
#:use-module (radix packages linux) #:use-module (radix packages linux)
#:use-module (gnu)
#:use-module (gnu services) #:use-module (gnu services)
#:use-module (gnu services shepherd) #:use-module (gnu services shepherd)
#:use-module (gnu services configuration)
#:use-module (guix gexp) #:use-module (guix gexp)
#:use-module (guix records) #:use-module (guix records)
#:use-module (ice-9 curried-definitions)
#:export (thinkfan-configuration #:export (thinkfan-configuration
make-thinkfan-configuration make-thinkfan-configuration
thinkfan-configuration? thinkfan-configuration?
thinkfan-configuration-requirement
thinkfan-configuration-pid-file thinkfan-configuration-pid-file
thinkfan-configuration-config-file thinkfan-configuration-config-file
thinkfan-configuration-log-file thinkfan-configuration-log-file
thinkfan-configuration-respawn
thinkfan-configuration-extra-options thinkfan-configuration-extra-options
thinkfan-shepherd-service thinkfan-shepherd-service
thinkfan-service-type)) thinkfan-service-type))
(define-record-type* <thinkfan-configuration> (define ((list-of predicate) x)
thinkfan-configuration make-thinkfan-configuration (null? (filter (negate predicate) x)))
thinkfan-configuration?
(requirement thinkfan-configuration-requirement ; list of symbols
(default '(user-processes)))
(pid-file thinkfan-configuration-pid-file ; string
(default "/var/run/thinkfan.pid"))
(config-file thinkfan-configuration-config-file ; string
(default "/etc/thinkfan.conf"))
(log-file thinkfan-configuration-log-file ; string
(default "/var/log/thinkfan.log"))
(respawn? thinkfan-configuration-respawn? ; boolean
(default #t))
(extra-options thinkfan-configuration-extra-options ; list of strings
(default '())))
(define (thinkfan-shepherd-service config) (define list-of-symbols?
(match-record config <thinkfan-configuration> (list-of symbol?))
(requirement pid-file config-file log-file respawn? extra-options)
(define list-of-strings?
(list-of string?))
(define-configuration/no-serialization thinkfan-configuration
(pid-file
(string "/var/run/thinkfan.pid")
"Where to store the PID file.")
(config-file
(string "/etc/thinkfan.conf")
"Configuration file to use.")
(log-file
(string "/var/log/thinkfan.log")
"File where thinkfan writes its log to.")
(extra-options
(list-of-strings '())
"This option provides an escape hatch for the user to provide
arbitrary command-line arguments to thinkfan as a list of strings."))
(define thinkfan-shepherd-service
(match-record-lambda <thinkfan-configuration>
(pid-file config-file log-file extra-options)
(list (shepherd-service (list (shepherd-service
(provision '(thinkfan)) (provision '(thinkfan))
(documentation (documentation
"Adjust fan level according to configured temperature limits.") "Adjust fan level according to configured temperature limits.")
(requirement requirement) (requirement '(user-processes kernel-module-loader))
(start #~(make-forkexec-constructor (start #~(make-forkexec-constructor
(list (string-append #$thinkfan-next "/sbin/thinkfan") (list (string-append #$thinkfan-next
(string-append "-c" #$config-file) "/sbin/thinkfan")
#$@extra-options) "-n" #$@extra-options
#:pid-file #$pid-file "-c" #$config-file)
#:log-file #$log-file)) #:log-file #$log-file
#:pid-file #$pid-file))
(stop #~(make-kill-destructor)) (stop #~(make-kill-destructor))
(one-shot? #t) (one-shot? #t)
(respawn? respawn?))))) (respawn? #t)))))
(define thinkfan-modprobe-config (define thinkfan-modprobe-config
(plain-file "thinkfan.conf" (plain-file "thinkfan.conf"