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,51 +135,53 @@
(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 (provision '(zfs-import))
(shepherd-service (requirement '(udev))
(provision '(file-system-zfs)) (documentation "Import ZFS storage pools.")
(requirement (start
`(zfs-import #~(make-system-constructor
,@(if volumes? '(zfs-volumes) '()) (string-join
,@(if auto-mount? '(zfs-mount) '()))) (list #$(file-append zfs "/sbin/zpool") "import" "-a" "-N"))))
(start #~(const #t)) (stop #~(const #f)))
(stop #~(const #f))) ,@(if volumes?
(shepherd-service (list
(provision '(zfs-import)) (shepherd-service
(requirement '(kernel-module-loader)) (provision '(zfs-volumes))
(start (requirement '(zfs-import))
#~(make-system-constructor (documentation "Wait for ZFS volume links to appear in /dev.")
(string-join (start
(list #$(file-append zfs "/sbin/zpool") "import" "-a" "-N")))) #~(make-system-constructor
(stop #~(const #f)))) (string-join
(if volumes? ;; TODO: Patch references within zfs package instead.
(list (list "PATH=/run/current-system/profile/bin:/run/current-system/profile/sbin"
(shepherd-service #$(file-append zfs "/bin/zvol_wait")))))
(provision '(zfs-volumes)) (stop #~(const #f))))
(requirement '(zfs-import)) '())
(start ,@(if auto-mount?
#~(make-system-constructor (list
(string-join (shepherd-service
;; TODO: Patch references within zfs package instead. (provision '(zfs-mount))
(list "PATH=/run/current-system/profile/bin:/run/current-system/profile/sbin" (requirement '(zfs-import))
#$(file-append zfs "/bin/zvol_wait"))))) (documentation "Mount all available ZFS file systems.")
(stop #~(const #f)))) (start
'()) #~(make-system-constructor
(if auto-mount? (string-join
(list (list #$(file-append zfs "/sbin/zfs") "mount" "-a" "-l"))))
(shepherd-service (stop
(provision '(zfs-mount)) #~(make-system-destructor
(requirement '(zfs-import)) (string-join
(start (list #$(file-append zfs "/sbin/zfs") "unmount" "-a"))))))
#~(make-system-constructor '())
(string-join ,(shepherd-service
(list #$(file-append zfs "/sbin/zfs") "mount" "-a" "-l")))) (provision '(file-system-zfs))
(stop (requirement
#~(make-system-destructor `(zfs-import
(string-join ,@(if volumes? '(zfs-volumes) '())
(list #$(file-append zfs "/sbin/zfs") "unmount" "-a")))))) ,@(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 "")))