gnu: linux-libre: Update to 4.10.8 [fixes CVE-2017-7184].
[jackhill/guix/guix.git] / gnu / services / dict.scm
CommitLineData
c3d38b2b
SB
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2016 Sou Bunnbu <iyzsong@gmail.com>
a1b48465 3;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
c3d38b2b
SB
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (gnu services dict)
21 #:use-module (guix gexp)
22 #:use-module (guix records)
23 #:use-module (gnu services)
24 #:use-module (gnu services shepherd)
25 #:use-module (gnu system shadow)
26 #:use-module ((gnu packages admin) #:select (shadow))
27 #:use-module (gnu packages dico)
28 #:use-module (gnu packages dictionaries)
29 #:use-module (srfi srfi-1)
30 #:use-module (srfi srfi-26)
31 #:use-module (ice-9 match)
32 #:export (dicod-service
24e96431 33 dicod-service-type
c3d38b2b
SB
34 dicod-configuration
35 dicod-database
36 %dicod-database:gcide))
37
38\f
39;;;
40;;; GNU Dico.
41;;;
42
43(define-record-type* <dicod-configuration>
44 dicod-configuration make-dicod-configuration
45 dicod-configuration?
46 (dico dicod-configuration-dico (default dico))
a1b48465
LC
47 (interfaces dicod-configuration-interfaces ;list of strings
48 (default '("localhost")))
c3d38b2b
SB
49 (databases dicod-configuration-databases
50 ;; list of <dicod-database>
51 (default (list %dicod-database:gcide))))
52
53(define-record-type* <dicod-database>
54 dicod-database make-dicod-database
55 dicod-database?
56 (name dicod-database-name)
57 (module dicod-database-module)
58 (options dicod-database-options (default '())))
59
60(define %dicod-database:gcide
61 (dicod-database
62 (name "gcide")
63 (module "gcide")
64 (options (list #~(string-append "dbdir=" #$gcide "/share/gcide")
65 "idxdir=/var/run/dicod"))))
66
67(define %dicod-accounts
68 (list (user-group
69 (name "dicod")
70 (system? #t))
71 (user-account
72 (name "dicod")
73 (group "dicod")
74 (system? #t)
75 (home-directory "/var/empty")
9e41130b 76 (shell (file-append shadow "/sbin/nologin")))))
c3d38b2b
SB
77
78(define (dicod-configuration-file config)
a1b48465 79 (define database->text
c3d38b2b 80 (match-lambda
a1b48465
LC
81 (($ <dicod-database> name module options)
82 `("
c3d38b2b
SB
83load-module " ,module ";
84database {
85 name \"" ,name "\";
86 handler \"" ,module
87 (string-join (list ,@options) " " 'prefix) "\";
a1b48465
LC
88}\n"))))
89
90 (define configuration->text
91 (match-lambda
92 (($ <dicod-configuration> dico (interfaces ...) databases)
93 (append `("listen ("
94 ,(string-join interfaces ", ") ");\n")
95 (append-map database->text databases)))))
96
97 (apply mixed-text-file "dicod.conf" (configuration->text config)))
c3d38b2b
SB
98
99(define %dicod-activation
100 #~(begin
101 (use-modules (guix build utils))
102 (let ((user (getpwnam "dicod"))
103 (rundir "/var/run/dicod"))
104 (mkdir-p rundir)
105 (chown rundir (passwd:uid user) (passwd:gid user)))))
106
107(define (dicod-shepherd-service config)
e5aade79
SB
108 (let ((dicod (file-append (dicod-configuration-dico config)
109 "/bin/dicod"))
110 (dicod.conf (dicod-configuration-file config)))
111 (list (shepherd-service
112 (provision '(dicod))
113 (documentation "Run the dicod daemon.")
114 (start #~(make-forkexec-constructor
115 (list #$dicod "--foreground"
116 (string-append "--config=" #$dicod.conf))
117 #:user "dicod" #:group "dicod"))
118 (stop #~(make-kill-destructor))))))
c3d38b2b
SB
119
120(define dicod-service-type
121 (service-type
122 (name 'dict)
123 (extensions
124 (list (service-extension account-service-type
125 (const %dicod-accounts))
126 (service-extension activation-service-type
127 (const %dicod-activation))
128 (service-extension shepherd-root-service-type
129 dicod-shepherd-service)))))
130
131(define* (dicod-service #:key (config (dicod-configuration)))
132 "Return a service that runs the @command{dicod} daemon, an implementation
133of DICT server (@pxref{Dicod,,, dico, GNU Dico Manual}).
134
135The optional @var{config} argument specifies the configuration for
136@command{dicod}, which should be a @code{<dicod-configuration>} object, by
137default it serves the GNU Collaborative International Dictonary of English.
138
139You can add @command{open localhost} to your @file{~/.dico} file to make
140@code{localhost} the default server for @command{dico}
141client (@pxref{Initialization File,,, dico, GNU Dico Manual})."
142 (service dicod-service-type config))