guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH Resend] services: dict.scm: Support more dicod configuration


From: Huang Ying
Subject: [PATCH Resend] services: dict.scm: Support more dicod configuration
Date: Tue, 7 Mar 2017 19:47:02 +0800

* gnu/services/dict.scm (<dicod-configuration>): Rename databases
  to items to reflect more general configuration.
  (<dicod-handler>): Add new record type to describe handler (module).
  (<dicod-database>): Add more fields.
  (dicod-configuration-file): Support convert more configuration items
  to config file.
---
 gnu/services/dict.scm | 50 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 40 insertions(+), 10 deletions(-)

diff --git a/gnu/services/dict.scm b/gnu/services/dict.scm
index 303067037..628ec9757 100644
--- a/gnu/services/dict.scm
+++ b/gnu/services/dict.scm
@@ -32,6 +32,7 @@
   #:export (dicod-service
             dicod-service-type
             dicod-configuration
+            dicod-handler
             dicod-database
             %dicod-database:gcide))
 
@@ -46,21 +47,29 @@
   (dico        dicod-configuration-dico       (default dico))
   (interfaces  dicod-configuration-interfaces     ;list of strings
                (default '("localhost")))
-  (databases   dicod-configuration-databases
-               ;; list of <dicod-database>
+  (items       dicod-configuration-items
+               ;; list of <dictod-handler> or <dicod-database>
                (default (list %dicod-database:gcide))))
 
+(define-record-type* <dicod-handler>
+  dicod-handler make-dicod-handler
+  dicod-handler?
+  (name        dicod-handler-name)
+  (module      dicod-handler-module          (default #f))
+  (options     dicod-handler-options         (default '())))
+
 (define-record-type* <dicod-database>
   dicod-database make-dicod-database
   dicod-database?
   (name        dicod-database-name)
-  (module      dicod-database-module)
+  (handler     dicod-database-handler)
+  (complex     dicod-database-complex        (default #f))
   (options     dicod-database-options        (default '())))
 
 (define %dicod-database:gcide
   (dicod-database
    (name "gcide")
-   (module "gcide")
+   (handler "gcide")
    (options (list #~(string-append "dbdir=" #$gcide "/share/gcide")
                   "idxdir=/var/run/dicod"))))
 
@@ -76,23 +85,44 @@
          (shell (file-append shadow "/sbin/nologin")))))
 
 (define (dicod-configuration-file config)
-  (define database->text
+  (define item->text
     (match-lambda
-      (($ <dicod-database> name module options)
+      (($ <dicod-handler> name #f '())
+       `("
+load-module " ,name ";"))
+      (($ <dicod-handler> name #f options)
+       (item->text (dicod-handler
+                    (name name)
+                    (module name)
+                    (options options))))
+      (($ <dicod-handler> name module options)
+       `("
+load-module " ,name " {
+   command \"" ,module (string-join (list ,@options) " " 'prefix) "\";
+}\n"))
+      (($ <dicod-database> name handler #f options)
+       (append
+        (item->text (dicod-handler
+                     (name handler)))
+        (item->text (dicod-database
+                     (name name)
+                     (handler handler)
+                     (complex #t)
+                     (options options)))))
+      (($ <dicod-database> name handler complex options)
        `("
-load-module " ,module ";
 database {
    name \"" ,name "\";
-   handler \"" ,module
+   handler \"" ,handler
    (string-join (list ,@options) " " 'prefix) "\";
 }\n"))))
 
   (define configuration->text
     (match-lambda
-      (($ <dicod-configuration> dico (interfaces ...) databases)
+      (($ <dicod-configuration> dico (interfaces ...) items)
        (append `("listen ("
                  ,(string-join interfaces ", ") ");\n")
-               (append-map database->text databases)))))
+               (append-map item->text items)))))
 
   (apply mixed-text-file "dicod.conf" (configuration->text config)))
 
-- 
2.12.0





reply via email to

[Prev in Thread] Current Thread [Next in Thread]