home: shepherd: Add daemonize? option to configuration.

* gnu/home/services/shepherd.scm (home-shepherd-configuration):
Add DAEMONIZE?.
(home-shepherd-configuration-file): Use CONFIG argument instead of two
separate SERVICES and SHEPHERD, respect DAEMONIZE?.
(ensure-shepherd-gexp, launch-shepherd-gexp,
shepherd-xdg-configuration-files): Adjust according to arguments changes in
HOME-SHEPHERD-CONFIGURATION-FILE.
This commit is contained in:
Andrew Tropin 2022-09-13 08:58:54 +03:00
parent f64825730f
commit 6cdde65bb5
No known key found for this signature in database
GPG Key ID: 2208D20958C1DEB0

View File

@ -54,19 +54,22 @@ (define-record-type* <home-shepherd-configuration>
(default shepherd-0.9)) ; package (default shepherd-0.9)) ; package
(auto-start? home-shepherd-configuration-auto-start? (auto-start? home-shepherd-configuration-auto-start?
(default #t)) (default #t))
(daemonize? home-shepherd-configuration-daemonize?
(default #t))
(services home-shepherd-configuration-services (services home-shepherd-configuration-services
(default '()))) (default '())))
(define (home-shepherd-configuration-file services shepherd) (define (home-shepherd-configuration-file config)
"Return the shepherd configuration file for SERVICES. SHEPHERD is used "Return the shepherd configuration file for SERVICES. SHEPHERD is used
as shepherd package." as shepherd package."
(assert-valid-graph services) (let* ((daemonize? (home-shepherd-configuration-daemonize? config))
(services (home-shepherd-configuration-services config))
(let ((files (map shepherd-service-file services)) (_ (assert-valid-graph services))
;; TODO: Add compilation of services, it can improve start (files (map shepherd-service-file services))
;; time. ;; TODO: Add compilation of services, it can improve start
;; (scm->go (cute scm->go <> shepherd)) ;; time.
) ;; (scm->go (cute scm->go <> shepherd))
)
(define config (define config
#~(begin #~(begin
(use-modules (srfi srfi-34) (use-modules (srfi srfi-34)
@ -76,7 +79,11 @@ (define config
(map (map
(lambda (file) (load file)) (lambda (file) (load file))
'#$files)) '#$files))
(action 'root 'daemonize)
#$@(if daemonize?
`((action 'root 'daemonize))
'())
(format #t "Starting services...~%") (format #t "Starting services...~%")
(let ((services-to-start (let ((services-to-start
'#$(append-map shepherd-service-provision '#$(append-map shepherd-service-provision
@ -92,8 +99,7 @@ (define config
(scheme-file "shepherd.conf" config))) (scheme-file "shepherd.conf" config)))
(define (launch-shepherd-gexp config) (define (launch-shepherd-gexp config)
(let* ((shepherd (home-shepherd-configuration-shepherd config)) (let* ((shepherd (home-shepherd-configuration-shepherd config)))
(services (home-shepherd-configuration-services config)))
(if (home-shepherd-configuration-auto-start? config) (if (home-shepherd-configuration-auto-start? config)
(with-imported-modules '((guix build utils)) (with-imported-modules '((guix build utils))
#~(unless (file-exists? #~(unless (file-exists?
@ -104,22 +110,22 @@ (define (launch-shepherd-gexp config)
(let ((log-dir (or (getenv "XDG_LOG_HOME") (let ((log-dir (or (getenv "XDG_LOG_HOME")
(format #f "~a/.local/var/log" (format #f "~a/.local/var/log"
(getenv "HOME"))))) (getenv "HOME")))))
;; TODO: Remove it, 0.9.2 creates it automatically?
((@ (guix build utils) mkdir-p) log-dir) ((@ (guix build utils) mkdir-p) log-dir)
(system* (system*
#$(file-append shepherd "/bin/shepherd") #$(file-append shepherd "/bin/shepherd")
"--logfile" "--logfile"
(string-append log-dir "/shepherd.log") (string-append log-dir "/shepherd.log")
"--config" "--config"
#$(home-shepherd-configuration-file services shepherd))))) #$(home-shepherd-configuration-file config)))))
#~""))) #~"")))
(define (reload-configuration-gexp config) (define (reload-configuration-gexp config)
(let* ((shepherd (home-shepherd-configuration-shepherd config)) (let* ((shepherd (home-shepherd-configuration-shepherd config)))
(services (home-shepherd-configuration-services config)))
#~(system* #~(system*
#$(file-append shepherd "/bin/herd") #$(file-append shepherd "/bin/herd")
"load" "root" "load" "root"
#$(home-shepherd-configuration-file services shepherd)))) #$(home-shepherd-configuration-file config))))
(define (ensure-shepherd-gexp config) (define (ensure-shepherd-gexp config)
#~(if (file-exists? #~(if (file-exists?
@ -131,10 +137,7 @@ (define (ensure-shepherd-gexp config)
#$(launch-shepherd-gexp config))) #$(launch-shepherd-gexp config)))
(define (shepherd-xdg-configuration-files config) (define (shepherd-xdg-configuration-files config)
(let* ((shepherd (home-shepherd-configuration-shepherd config)) `(("shepherd/init.scm" ,(home-shepherd-configuration-file config))))
(services (home-shepherd-configuration-services config)))
`(("shepherd/init.scm"
,(home-shepherd-configuration-file services shepherd)))))
(define-public home-shepherd-service-type (define-public home-shepherd-service-type
(service-type (name 'home-shepherd) (service-type (name 'home-shepherd)