1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016 Sou Bunnbu <iyzsong@gmail.com>
3 ;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
5 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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
36 %dicod-database:gcide))
43 (define-record-type* <dicod-configuration>
44 dicod-configuration make-dicod-configuration
46 (dico dicod-configuration-dico (default dico))
47 (interfaces dicod-configuration-interfaces ;list of strings
48 (default '("localhost")))
49 (databases dicod-configuration-databases
50 ;; list of <dicod-database>
51 (default (list %dicod-database:gcide))))
53 (define-record-type* <dicod-database>
54 dicod-database make-dicod-database
56 (name dicod-database-name)
57 (module dicod-database-module)
58 (options dicod-database-options (default '())))
60 (define %dicod-database:gcide
64 (options (list #~(string-append "dbdir=" #$gcide "/share/gcide")
65 "idxdir=/var/run/dicod"))))
67 (define %dicod-accounts
75 (home-directory "/var/empty")
76 (shell #~(string-append #$shadow "/sbin/nologin")))))
78 (define (dicod-configuration-file config)
79 (define database->text
81 (($ <dicod-database> name module options)
83 load-module " ,module ";
87 (string-join (list ,@options) " " 'prefix) "\";
90 (define configuration->text
92 (($ <dicod-configuration> dico (interfaces ...) databases)
94 ,(string-join interfaces ", ") ");\n")
95 (append-map database->text databases)))))
97 (apply mixed-text-file "dicod.conf" (configuration->text config)))
99 (define %dicod-activation
101 (use-modules (guix build utils))
102 (let ((user (getpwnam "dicod"))
103 (rundir "/var/run/dicod"))
105 (chown rundir (passwd:uid user) (passwd:gid user)))))
107 (define (dicod-shepherd-service config)
108 (list (shepherd-service
110 (documentation "Run the dicod daemon.")
111 (start #~(make-forkexec-constructor
112 (list (string-append #$dico "/bin/dicod") "--foreground"
114 "--config=" #$(dicod-configuration-file config)))
115 #:user "dicod" #:group "dicod"))
116 (stop #~(make-kill-destructor)))))
118 (define dicod-service-type
122 (list (service-extension account-service-type
123 (const %dicod-accounts))
124 (service-extension activation-service-type
125 (const %dicod-activation))
126 (service-extension shepherd-root-service-type
127 dicod-shepherd-service)))))
129 (define* (dicod-service #:key (config (dicod-configuration)))
130 "Return a service that runs the @command{dicod} daemon, an implementation
131 of DICT server (@pxref{Dicod,,, dico, GNU Dico Manual}).
133 The optional @var{config} argument specifies the configuration for
134 @command{dicod}, which should be a @code{<dicod-configuration>} object, by
135 default it serves the GNU Collaborative International Dictonary of English.
137 You can add @command{open localhost} to your @file{~/.dico} file to make
138 @code{localhost} the default server for @command{dico}
139 client (@pxref{Initialization File,,, dico, GNU Dico Manual})."
140 (service dicod-service-type config))