services: sing-box: Support setting config directory.

* modules/rosenthal/services/networking.scm (<sing-box-configuration>)
[config-directory]: New field.
(sing-box-shepherd-service): Use it.

Signed-off-by: Hilton Chain <hako@ultrarare.space>
Modified-by: Hilton Chain <hako@ultrarare.space>
Merges: #56
This commit is contained in:
solitudealma authored and Hilton Chain committed 2026-09-12 13:37:36 +08:00
1 parent 91f2eac90a
commit ab3698c4ad
1 file changed
+35 -15
+35 -15
View File
@@ -7,7 +7,9 @@
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (srfi srfi-26) #:use-module (srfi srfi-26)
;; Utilities ;; Utilities
#:use-module (guix diagnostics)
#:use-module (guix gexp) #:use-module (guix gexp)
#:use-module (guix i18n)
#:use-module (guix records) #:use-module (guix records)
#:use-module (rosenthal utils predicates) #:use-module (rosenthal utils predicates)
;; Guix System ;; Guix System
@@ -91,12 +93,18 @@
;;; sing-box ;;; sing-box
;;; ;;;
(define-maybe file-object)
(define-maybe string)
(define-configuration/no-serialization sing-box-configuration (define-configuration/no-serialization sing-box-configuration
(sing-box (sing-box
(file-like sing-box) (file-like sing-box)
"") "")
(config-file (config-file
file-object maybe-file-object
"")
(config-directory
maybe-string
"") "")
(data-directory (data-directory
(string "/var/lib/sing-box") (string "/var/lib/sing-box")
@@ -136,21 +144,33 @@
(define sing-box-shepherd-service (define sing-box-shepherd-service
(match-record-lambda <sing-box-configuration> (match-record-lambda <sing-box-configuration>
(sing-box data-directory config-file (sing-box data-directory config-file config-directory
shepherd-provision shepherd-requirement log-file auto-start?) shepherd-provision shepherd-requirement log-file auto-start?)
(list (shepherd-service (let ((config-file-set? (maybe-value-set? config-file))
(provision shepherd-provision) (config-dir-set? (maybe-value-set? config-directory)))
(requirement `(user-processes ,@shepherd-requirement)) (when (eqv? config-file-set? config-dir-set?)
(start (leave (G_ "'~a': exactly one of '~a' or '~a' must be set~%")
#~(make-forkexec-constructor "sing-box-configuration"
(list #$(file-append sing-box "/bin/sing-box") "config-file"
"--config" #$config-file "config-directory"))
"--directory" #$data-directory (list (shepherd-service
"--disable-color" (provision shepherd-provision)
"run") (requirement `(user-processes ,@shepherd-requirement))
#:log-file #$log-file)) (start
(stop #~(make-kill-destructor)) #~(make-forkexec-constructor
(auto-start? auto-start?))))) (list #$(file-append sing-box "/bin/sing-box")
#$@(if config-file-set?
(list "--config" config-file)
'())
#$@(if config-dir-set?
(list "--config-directory" config-directory)
'())
"--directory" #$data-directory
"--disable-color"
"run")
#:log-file #$log-file))
(stop #~(make-kill-destructor))
(auto-start? auto-start?))))))
(define sing-box-service-type (define sing-box-service-type
(service-type (service-type