From 9af7ecd9591b4eff41389291bbc586dcf09e2665 Mon Sep 17 00:00:00 2001 From: Huang Ying Date: Thu, 30 Mar 2017 19:13:34 +0800 Subject: services: dicod: Allow the configuration of "handlers". MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/services/dict.scm ()[handlers]: New field. (): New record type. (): Add fields. (dicod-configuration-file): Support convert handlers and enhanced databases. configuration to config file. * doc/guix.texi (Miscellaneous Services): Update accordingly. Signed-off-by: Ludovic Courtès --- gnu/services/dict.scm | 54 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) (limited to 'gnu/services') diff --git a/gnu/services/dict.scm b/gnu/services/dict.scm index 303067037f..64de111511 100644 --- a/gnu/services/dict.scm +++ b/gnu/services/dict.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016 Sou Bunnbu -;;; Copyright © 2016 Ludovic Courtès +;;; Copyright © 2016, 2017 Ludovic Courtès +;;; Copyright © 2017 Huang Ying ;;; ;;; This file is part of GNU Guix. ;;; @@ -32,6 +33,7 @@ #:export (dicod-service dicod-service-type dicod-configuration + dicod-handler dicod-database %dicod-database:gcide)) @@ -46,21 +48,30 @@ (dico dicod-configuration-dico (default dico)) (interfaces dicod-configuration-interfaces ;list of strings (default '("localhost"))) - (databases dicod-configuration-databases - ;; list of + (handlers dicod-configuration-handlers ;list of + (default '())) + (databases dicod-configuration-databases ;list of (default (list %dicod-database:gcide)))) +(define-record-type* + 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 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,22 +87,47 @@ (shell (file-append shadow "/sbin/nologin"))))) (define (dicod-configuration-file config) + (define handler->text + (match-lambda + (($ name #f '()) + `(" +load-module " ,name ";")) + (($ name #f options) + (handler->text (dicod-handler + (name name) + (module name) + (options options)))) + (($ name module options) + `(" +load-module " ,name " { + command \"" ,module (string-join (list ,@options) " " 'prefix) "\"; +}\n")))) + (define database->text (match-lambda - (($ name module options) + (($ name handler #f options) + (append + (handler->text (dicod-handler + (name handler))) + (database->text (dicod-database + (name name) + (handler handler) + (complex? #t) + (options options))))) + (($ 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 - (($ dico (interfaces ...) databases) + (($ dico (interfaces ...) handlers databases) (append `("listen (" ,(string-join interfaces ", ") ");\n") + (append-map handler->text handlers) (append-map database->text databases))))) (apply mixed-text-file "dicod.conf" (configuration->text config))) -- cgit v1.2.3