services: zfs: Improve style.

This commit is contained in:
Hilton Chain 2026-03-29 13:37:33 +08:00
parent a238fc8c28
commit 760c336362
No known key found for this signature in database
GPG Key ID: ACC66D09CA528292

View File

@ -112,13 +112,13 @@
"ZFS package to use.") "ZFS package to use.")
(kernel-has-zfs-module? (kernel-has-zfs-module?
(boolean #f) (boolean #f)
"Whether or not ZFS modules have already been built into the kernel.") "Whether ZFS module has already been built into the kernel.")
(volumes? (volumes?
(boolean #f) (boolean #f)
"Wait for ZFS volumes.") "Wait for ZFS volumes to show up.")
(auto-mount? (auto-mount?
(boolean #t) (boolean #t)
"Mount all available ZFS file systems.")) "Auto-mount ZFS datasets."))
(define zfs-linux-loadable-module-service (define zfs-linux-loadable-module-service
(match-record-lambda <zfs-configuration> (match-record-lambda <zfs-configuration>
@ -135,29 +135,21 @@
(define zfs-shepherd-service (define zfs-shepherd-service
(match-record-lambda <zfs-configuration> (match-record-lambda <zfs-configuration>
(zfs volumes? auto-mount?) (zfs volumes? auto-mount?)
(append `(,(shepherd-service
(list
(shepherd-service
(provision '(file-system-zfs))
(requirement
`(zfs-import
,@(if volumes? '(zfs-volumes) '())
,@(if auto-mount? '(zfs-mount) '())))
(start #~(const #t))
(stop #~(const #f)))
(shepherd-service
(provision '(zfs-import)) (provision '(zfs-import))
(requirement '(kernel-module-loader)) (requirement '(udev))
(documentation "Import ZFS storage pools.")
(start (start
#~(make-system-constructor #~(make-system-constructor
(string-join (string-join
(list #$(file-append zfs "/sbin/zpool") "import" "-a" "-N")))) (list #$(file-append zfs "/sbin/zpool") "import" "-a" "-N"))))
(stop #~(const #f)))) (stop #~(const #f)))
(if volumes? ,@(if volumes?
(list (list
(shepherd-service (shepherd-service
(provision '(zfs-volumes)) (provision '(zfs-volumes))
(requirement '(zfs-import)) (requirement '(zfs-import))
(documentation "Wait for ZFS volume links to appear in /dev.")
(start (start
#~(make-system-constructor #~(make-system-constructor
(string-join (string-join
@ -166,11 +158,12 @@
#$(file-append zfs "/bin/zvol_wait"))))) #$(file-append zfs "/bin/zvol_wait")))))
(stop #~(const #f)))) (stop #~(const #f))))
'()) '())
(if auto-mount? ,@(if auto-mount?
(list (list
(shepherd-service (shepherd-service
(provision '(zfs-mount)) (provision '(zfs-mount))
(requirement '(zfs-import)) (requirement '(zfs-import))
(documentation "Mount all available ZFS file systems.")
(start (start
#~(make-system-constructor #~(make-system-constructor
(string-join (string-join
@ -179,7 +172,16 @@
#~(make-system-destructor #~(make-system-destructor
(string-join (string-join
(list #$(file-append zfs "/sbin/zfs") "unmount" "-a")))))) (list #$(file-append zfs "/sbin/zfs") "unmount" "-a"))))))
'())))) '())
,(shepherd-service
(provision '(file-system-zfs))
(requirement
`(zfs-import
,@(if volumes? '(zfs-volumes) '())
,@(if auto-mount? '(zfs-mount) '())))
(documentation "Take care of ZFS file systems.")
(start #~(const #t))
(stop #~(const #f))))))
(define zfs-service-type (define zfs-service-type
(service-type (service-type
@ -189,13 +191,11 @@
zfs-linux-loadable-module-service) zfs-linux-loadable-module-service)
(service-extension udev-service-type (service-extension udev-service-type
add-zfs-package) add-zfs-package)
(service-extension kernel-module-loader-service-type (service-extension profile-service-type
(const '("zfs"))) add-zfs-package)
(service-extension shepherd-root-service-type (service-extension shepherd-root-service-type
zfs-shepherd-service) zfs-shepherd-service)
(service-extension user-processes-service-type (service-extension user-processes-service-type
(const '(file-system-zfs))) (const '(file-system-zfs)))))
(service-extension profile-service-type
add-zfs-package)))
(default-value (zfs-configuration)) (default-value (zfs-configuration))
(description ""))) (description "")))