diff options
| author | Huang Ying <huang.ying.caritas@gmail.com> | 2017-03-30 19:13:34 +0800 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2017-04-01 00:45:18 +0200 |
| commit | 9af7ecd9591b4eff41389291bbc586dcf09e2665 (patch) | |
| tree | dd36fdace6ec88b026d5a973a17b776a1c1177a9 /gnu | |
| parent | bacc1d26c6e49f65b9c55296e3643999e7e8bc72 (diff) | |
services: dicod: Allow the configuration of "handlers".
* gnu/services/dict.scm (<dicod-configuration>)[handlers]: New field.
(<dicod-handler>): New record type.
(<dicod-database>): 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 <ludo@gnu.org>
Diffstat (limited to 'gnu')
| -rw-r--r-- | gnu/services/dict.scm | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/gnu/services/dict.scm b/gnu/services/dict.scm index 303067037f6..64de1115116 100644 --- a/gnu/services/dict.scm +++ b/gnu/services/dict.scm | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2016 Sou Bunnbu <iyzsong@gmail.com> | 2 | ;;; Copyright © 2016 Sou Bunnbu <iyzsong@gmail.com> |
| 3 | ;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org> | 3 | ;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org> |
| 4 | ;;; Copyright © 2017 Huang Ying <huang.ying.caritas@gmail.com> | ||
| 4 | ;;; | 5 | ;;; |
| 5 | ;;; This file is part of GNU Guix. | 6 | ;;; This file is part of GNU Guix. |
| 6 | ;;; | 7 | ;;; |
| @@ -32,6 +33,7 @@ | |||
| 32 | #:export (dicod-service | 33 | #:export (dicod-service |
| 33 | dicod-service-type | 34 | dicod-service-type |
| 34 | dicod-configuration | 35 | dicod-configuration |
| 36 | dicod-handler | ||
| 35 | dicod-database | 37 | dicod-database |
| 36 | %dicod-database:gcide)) | 38 | %dicod-database:gcide)) |
| 37 | 39 | ||
| @@ -46,21 +48,30 @@ | |||
| 46 | (dico dicod-configuration-dico (default dico)) | 48 | (dico dicod-configuration-dico (default dico)) |
| 47 | (interfaces dicod-configuration-interfaces ;list of strings | 49 | (interfaces dicod-configuration-interfaces ;list of strings |
| 48 | (default '("localhost"))) | 50 | (default '("localhost"))) |
| 49 | (databases dicod-configuration-databases | 51 | (handlers dicod-configuration-handlers ;list of <dicod-handler> |
| 50 | ;; list of <dicod-database> | 52 | (default '())) |
| 53 | (databases dicod-configuration-databases ;list of <dicod-database> | ||
| 51 | (default (list %dicod-database:gcide)))) | 54 | (default (list %dicod-database:gcide)))) |
| 52 | 55 | ||
| 56 | (define-record-type* <dicod-handler> | ||
| 57 | dicod-handler make-dicod-handler | ||
| 58 | dicod-handler? | ||
| 59 | (name dicod-handler-name) | ||
| 60 | (module dicod-handler-module (default #f)) | ||
| 61 | (options dicod-handler-options (default '()))) | ||
| 62 | |||
| 53 | (define-record-type* <dicod-database> | 63 | (define-record-type* <dicod-database> |
| 54 | dicod-database make-dicod-database | 64 | dicod-database make-dicod-database |
| 55 | dicod-database? | 65 | dicod-database? |
| 56 | (name dicod-database-name) | 66 | (name dicod-database-name) |
| 57 | (module dicod-database-module) | 67 | (handler dicod-database-handler) |
| 68 | (complex? dicod-database-complex? (default #f)) | ||
| 58 | (options dicod-database-options (default '()))) | 69 | (options dicod-database-options (default '()))) |
| 59 | 70 | ||
| 60 | (define %dicod-database:gcide | 71 | (define %dicod-database:gcide |
| 61 | (dicod-database | 72 | (dicod-database |
| 62 | (name "gcide") | 73 | (name "gcide") |
| 63 | (module "gcide") | 74 | (handler "gcide") |
| 64 | (options (list #~(string-append "dbdir=" #$gcide "/share/gcide") | 75 | (options (list #~(string-append "dbdir=" #$gcide "/share/gcide") |
| 65 | "idxdir=/var/run/dicod")))) | 76 | "idxdir=/var/run/dicod")))) |
| 66 | 77 | ||
| @@ -76,22 +87,47 @@ | |||
| 76 | (shell (file-append shadow "/sbin/nologin"))))) | 87 | (shell (file-append shadow "/sbin/nologin"))))) |
| 77 | 88 | ||
| 78 | (define (dicod-configuration-file config) | 89 | (define (dicod-configuration-file config) |
| 90 | (define handler->text | ||
| 91 | (match-lambda | ||
| 92 | (($ <dicod-handler> name #f '()) | ||
| 93 | `(" | ||
| 94 | load-module " ,name ";")) | ||
| 95 | (($ <dicod-handler> name #f options) | ||
| 96 | (handler->text (dicod-handler | ||
| 97 | (name name) | ||
| 98 | (module name) | ||
| 99 | (options options)))) | ||
| 100 | (($ <dicod-handler> name module options) | ||
| 101 | `(" | ||
| 102 | load-module " ,name " { | ||
| 103 | command \"" ,module (string-join (list ,@options) " " 'prefix) "\"; | ||
| 104 | }\n")))) | ||
| 105 | |||
| 79 | (define database->text | 106 | (define database->text |
| 80 | (match-lambda | 107 | (match-lambda |
| 81 | (($ <dicod-database> name module options) | 108 | (($ <dicod-database> name handler #f options) |
| 109 | (append | ||
| 110 | (handler->text (dicod-handler | ||
| 111 | (name handler))) | ||
| 112 | (database->text (dicod-database | ||
| 113 | (name name) | ||
| 114 | (handler handler) | ||
| 115 | (complex? #t) | ||
| 116 | (options options))))) | ||
| 117 | (($ <dicod-database> name handler complex? options) | ||
| 82 | `(" | 118 | `(" |
| 83 | load-module " ,module "; | ||
| 84 | database { | 119 | database { |
| 85 | name \"" ,name "\"; | 120 | name \"" ,name "\"; |
| 86 | handler \"" ,module | 121 | handler \"" ,handler |
| 87 | (string-join (list ,@options) " " 'prefix) "\"; | 122 | (string-join (list ,@options) " " 'prefix) "\"; |
| 88 | }\n")))) | 123 | }\n")))) |
| 89 | 124 | ||
| 90 | (define configuration->text | 125 | (define configuration->text |
| 91 | (match-lambda | 126 | (match-lambda |
| 92 | (($ <dicod-configuration> dico (interfaces ...) databases) | 127 | (($ <dicod-configuration> dico (interfaces ...) handlers databases) |
| 93 | (append `("listen (" | 128 | (append `("listen (" |
| 94 | ,(string-join interfaces ", ") ");\n") | 129 | ,(string-join interfaces ", ") ");\n") |
| 130 | (append-map handler->text handlers) | ||
| 95 | (append-map database->text databases))))) | 131 | (append-map database->text databases))))) |
| 96 | 132 | ||
| 97 | (apply mixed-text-file "dicod.conf" (configuration->text config))) | 133 | (apply mixed-text-file "dicod.conf" (configuration->text config))) |
