1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org>
3 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
4 ;;; Copyright © 2015, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (gnu services messaging)
22 #:use-module (gnu packages messaging)
23 #:use-module (gnu packages admin)
24 #:use-module (gnu services)
25 #:use-module (gnu services shepherd)
26 #:use-module (gnu services configuration)
27 #:use-module (gnu system shadow)
28 #:use-module (guix gexp)
29 #:use-module (guix modules)
30 #:use-module (guix records)
31 #:use-module (guix packages)
32 #:use-module (srfi srfi-1)
33 #:use-module (srfi srfi-35)
34 #:use-module (ice-9 match)
35 #:export (prosody-service-type
37 opaque-prosody-configuration
39 virtualhost-configuration
40 int-component-configuration
41 ext-component-configuration
46 %default-modules-enabled
47 prosody-configuration-pidfile
50 bitlbee-configuration?
52 bitlbee-service-type))
56 ;;; Messaging services.
60 (define-syntax define-all-configurations
62 (define-syntax-rule (id ctx parts ...)
63 "Assemble PARTS into a raw (unhygienic) identifier."
64 (datum->syntax ctx (symbol-append (syntax->datum parts) ...)))
65 (define (make-pred arg)
66 (lambda (field target)
67 (and (memq (syntax->datum target) `(common ,arg)) field)))
69 ((_ stem (field (field-type def) doc target) ...)
70 (with-syntax (((new-field-type ...)
71 (map (lambda (field-type target)
72 (if (and (eq? 'common (syntax->datum target))
76 (syntax->datum field-type)))))
77 (id #'stem #'maybe- field-type) field-type))
78 #'(field-type ...) #'(target ...)))
80 (map (lambda (def target)
81 (if (eq? 'common (syntax->datum target))
83 #'(def ...) #'(target ...)))
85 (map (lambda (doc target)
86 (if (eq? 'common (syntax->datum target))
88 #'(doc ...) #'(target ...))))
90 (define #,(id #'stem #'common-fields)
91 '(#,@(filter-map (make-pred #f) #'(field ...) #'(target ...))))
92 (define-configuration #,(id #'stem #'prosody-configuration)
93 #,@(filter-map (make-pred 'global)
94 #'((field (field-type def) doc) ...)
96 (define-configuration #,(id #'stem #'virtualhost-configuration)
97 #,@(filter-map (make-pred 'virtualhost)
98 #'((field (new-field-type new-def) new-doc) ...)
100 (define-configuration #,(id #'stem #'int-component-configuration)
101 #,@(filter-map (make-pred 'int-component)
102 #'((field (new-field-type new-def) new-doc) ...)
104 (define-configuration #,(id #'stem #'ext-component-configuration)
105 #,@(filter-map (make-pred 'ext-component)
106 #'((field (new-field-type new-def) new-doc) ...)
107 #'(target ...)))))))))
109 (define (uglify-field-name field-name)
110 (let ((str (symbol->string field-name)))
111 (string-join (string-split (if (string-suffix? "?" str)
112 (substring str 0 (1- (string-length str)))
117 (define (serialize-field field-name val)
118 #~(format #f "~a = ~a;\n" #$(uglify-field-name field-name) #$val))
119 (define (serialize-field-list field-name val)
120 (serialize-field field-name #~(format #f "{\n~@{~a;\n~}}" #$@val)))
122 (define (serialize-boolean field-name val)
123 (serialize-field field-name (if val "true" "false")))
124 (define-maybe boolean)
126 (define (string-or-boolean? val)
127 (or (string? val) (boolean? val)))
128 (define (serialize-string-or-boolean field-name val)
130 (serialize-string field-name val)
131 (serialize-boolean field-name val)))
133 (define (non-negative-integer? val)
134 (and (exact-integer? val) (not (negative? val))))
135 (define (serialize-non-negative-integer field-name val)
136 (serialize-field field-name (number->string val)))
137 (define-maybe non-negative-integer)
139 (define (non-negative-integer-list? val)
140 (and (list? val) (and-map non-negative-integer? val)))
141 (define (serialize-non-negative-integer-list field-name val)
142 (serialize-field-list field-name (map number->string val)))
143 (define-maybe non-negative-integer-list)
145 (define (enclose-quotes s)
146 #~(string-append "\"" #$s "\""))
147 (define (serialize-string field-name val)
148 (serialize-field field-name (enclose-quotes val)))
149 (define-maybe string)
151 (define (string-list? val)
154 (and (string? x) (not (string-index x #\,))))
156 (define (serialize-string-list field-name val)
157 (serialize-field-list field-name (map enclose-quotes val)))
158 (define-maybe string-list)
160 (define (module-list? val)
162 (define (serialize-module-list field-name val)
163 (serialize-string-list field-name val))
164 (define-maybe module-list)
166 (define (file-name? val)
168 (string-prefix? "/" val)))
169 (define (serialize-file-name field-name val)
170 (serialize-string field-name val))
171 (define-maybe file-name)
173 (define (file-name-list? val)
174 (and (list? val) (and-map file-name? val)))
175 (define (serialize-file-name-list field-name val)
176 (serialize-string-list field-name val))
177 (define-maybe file-name)
179 (define (file-object? val)
180 (or (file-like? val) (file-name? val)))
181 (define (serialize-file-object field-name val)
182 (serialize-string field-name val))
183 (define-maybe file-object)
185 (define (file-object-list? val)
186 (and (list? val) (and-map file-object? val)))
187 (define (serialize-file-object-list field-name val)
188 (serialize-string-list field-name val))
189 (define-maybe file-object)
191 (define (raw-content? val)
192 (not (eq? val 'disabled)))
193 (define (serialize-raw-content field-name val)
195 (define-maybe raw-content)
197 (define-configuration mod-muc-configuration
199 (string "Prosody Chatrooms")
200 "The name to return in service discovery responses.")
202 (restrict-room-creation
203 (string-or-boolean #f)
204 "If @samp{#t}, this will only allow admins to create new chatrooms.
205 Otherwise anyone can create a room. The value @samp{\"local\"} restricts room
206 creation to users on the service's parent domain. E.g. @samp{user@@example.com}
207 can create rooms on @samp{rooms.example.com}. The value @samp{\"admin\"}
208 restricts to service administrators only.")
210 (max-history-messages
211 (non-negative-integer 20)
212 "Maximum number of history messages that will be sent to the member that has
213 just joined the room."))
214 (define (serialize-mod-muc-configuration field-name val)
215 (serialize-configuration val mod-muc-configuration-fields))
216 (define-maybe mod-muc-configuration)
218 (define-configuration ssl-configuration
220 (maybe-string 'disabled)
221 "This determines what handshake to use.")
224 (maybe-file-name 'disabled)
225 "Path to your private key file.")
228 (maybe-file-name 'disabled)
229 "Path to your certificate file.")
232 (file-object "/etc/ssl/certs")
233 "Path to directory containing root certificates that you wish Prosody to
234 trust when verifying the certificates of remote servers.")
237 (maybe-file-object 'disabled)
238 "Path to a file containing root certificates that you wish Prosody to trust.
239 Similar to @code{capath} but with all certificates concatenated together.")
242 (maybe-string-list 'disabled)
243 "A list of verification options (these mostly map to OpenSSL's
244 @code{set_verify()} flags).")
247 (maybe-string-list 'disabled)
248 "A list of general options relating to SSL/TLS. These map to OpenSSL's
249 @code{set_options()}. For a full list of options available in LuaSec, see the
253 (maybe-non-negative-integer 'disabled)
254 "How long a chain of certificate authorities to check when looking for a
255 trusted root certificate.")
258 (maybe-string 'disabled)
259 "An OpenSSL cipher string. This selects what ciphers Prosody will offer to
260 clients, and in what order.")
263 (maybe-file-name 'disabled)
264 "A path to a file containing parameters for Diffie-Hellman key exchange. You
265 can create such a file with:
266 @code{openssl dhparam -out /etc/prosody/certs/dh-2048.pem 2048}")
269 (maybe-string 'disabled)
270 "Curve for Elliptic curve Diffie-Hellman. Prosody's default is
271 @samp{\"secp384r1\"}.")
274 (maybe-string-list 'disabled)
275 "A list of \"extra\" verification options.")
278 (maybe-string 'disabled)
279 "Password for encrypted private keys."))
280 (define (serialize-ssl-configuration field-name val)
281 #~(format #f "ssl = {\n~a};\n"
282 #$(serialize-configuration val ssl-configuration-fields)))
283 (define-maybe ssl-configuration)
285 (define %default-modules-enabled
303 ;; Guile bug. Use begin wrapper, because otherwise virtualhost-configuration
304 ;; is assumed to be a function. See
305 ;; https://www.gnu.org/software/guile/manual/html_node/R6RS-Incompatibilities.html
307 (define (virtualhost-configuration-list? val)
308 (and (list? val) (and-map virtualhost-configuration? val)))
309 (define (serialize-virtualhost-configuration-list l)
311 #$@(map (lambda (val)
312 (serialize-virtualhost-configuration val)) l)))
314 (define (int-component-configuration-list? val)
315 (and (list? val) (and-map int-component-configuration? val)))
316 (define (serialize-int-component-configuration-list l)
318 #$@(map (lambda (val)
319 (serialize-int-component-configuration val)) l)))
321 (define (ext-component-configuration-list? val)
322 (and (list? val) (and-map ext-component-configuration? val)))
323 (define (serialize-ext-component-configuration-list l)
325 #$@(map (lambda (val)
326 (serialize-ext-component-configuration val)) l)))
328 (define-all-configurations prosody-configuration
331 "The Prosody package."
335 (file-name "/var/lib/prosody")
336 "Location of the Prosody data storage directory. See
337 @url{https://prosody.im/doc/configure}."
341 (file-object-list '())
342 "Additional plugin directories. They are searched in all the specified
343 paths in order. See @url{https://prosody.im/doc/plugins_directory}."
347 (file-name "/etc/prosody/certs")
348 "Every virtual host and component needs a certificate so that clients and
349 servers can securely verify its identity. Prosody will automatically load
350 certificates/keys from the directory specified here."
355 "This is a list of accounts that are admins for the server. Note that you
356 must create the accounts separately. See @url{https://prosody.im/doc/admins} and
357 @url{https://prosody.im/doc/creating_accounts}.
358 Example: @code{(admins '(\"user1@@example.com\" \"user2@@example.net\"))}"
363 "Enable use of libevent for better performance under high load. See
364 @url{https://prosody.im/doc/libevent}."
368 (module-list %default-modules-enabled)
369 "This is the list of modules Prosody will load on startup. It looks for
370 @code{mod_modulename.lua} in the plugins folder, so make sure that exists too.
371 Documentation on modules can be found at:
372 @url{https://prosody.im/doc/modules}."
377 "@samp{\"offline\"}, @samp{\"c2s\"} and @samp{\"s2s\"} are auto-loaded, but
378 should you want to disable them then add them to this list."
382 (file-object "/var/lib/prosody/sharedgroups.txt")
383 "Path to a text file where the shared groups are defined. If this path is
384 empty then @samp{mod_groups} does nothing. See
385 @url{https://prosody.im/doc/modules/mod_groups}."
390 "Disable account creation by default, for security. See
391 @url{https://prosody.im/doc/creating_accounts}."
395 (maybe-ssl-configuration (ssl-configuration))
396 "These are the SSL/TLS-related settings. Most of them are disabled so to
397 use Prosody's defaults. If you do not completely understand these options, do
398 not add them to your config, it is easy to lower the security of your server
399 using them. See @url{https://prosody.im/doc/advanced_ssl_config}."
402 (c2s-require-encryption?
404 "Whether to force all client-to-server connections to be encrypted or not.
405 See @url{https://prosody.im/doc/modules/mod_tls}."
408 (disable-sasl-mechanisms
409 (string-list '("DIGEST-MD5"))
410 "Set of mechanisms that will never be offered. See
411 @url{https://prosody.im/doc/modules/mod_saslauth}."
414 (s2s-require-encryption?
416 "Whether to force all server-to-server connections to be encrypted or not.
417 See @url{https://prosody.im/doc/modules/mod_tls}."
422 "Whether to require encryption and certificate authentication. This
423 provides ideal security, but requires servers you communicate with to support
424 encryption AND present valid, trusted certificates. See
425 @url{https://prosody.im/doc/s2s#security}."
428 (s2s-insecure-domains
430 "Many servers don't support encryption or have invalid or self-signed
431 certificates. You can list domains here that will not be required to
432 authenticate using certificates. They will be authenticated using DNS. See
433 @url{https://prosody.im/doc/s2s#security}."
438 "Even if you leave @code{s2s-secure-auth?} disabled, you can still require
439 valid certificates for some domains by specifying a list here. See
440 @url{https://prosody.im/doc/s2s#security}."
444 (string "internal_plain")
445 "Select the authentication backend to use. The default provider stores
446 passwords in plaintext and uses Prosody's configured data storage to store the
447 authentication data. If you do not trust your server please see
448 @url{https://prosody.im/doc/modules/mod_auth_internal_hashed} for information
449 about using the hashed backend. See also
450 @url{https://prosody.im/doc/authentication}"
453 ;; TODO: Handle more complicated log structures.
455 (maybe-string "*syslog")
456 "Set logging options. Advanced logging configuration is not yet supported
457 by the GuixSD Prosody Service. See @url{https://prosody.im/doc/logging}."
461 (file-name "/var/run/prosody/prosody.pid")
462 "File to write pid in. See @url{https://prosody.im/doc/modules/mod_posix}."
465 (http-max-content-size
466 (maybe-non-negative-integer 'disabled)
467 "Maximum allowed size of the HTTP body (in bytes)."
471 (maybe-string 'disabled)
472 "Some modules expose their own URL in various ways. This URL is built
473 from the protocol, host and port used. If Prosody sits behind a proxy, the
474 public URL will be @code{http-external-url} instead. See
475 @url{https://prosody.im/doc/http#external_url}."
479 (virtualhost-configuration-list
480 (list (virtualhost-configuration
481 (domain "localhost"))))
482 "A host in Prosody is a domain on which user accounts can be created. For
483 example if you want your users to have addresses like
484 @samp{\"john.smith@@example.com\"} then you need to add a host
485 @samp{\"example.com\"}. All options in this list will apply only to this host.
487 Note: the name \"virtual\" host is used in configuration to avoid confusion with
488 the actual physical host that Prosody is installed on. A single Prosody
489 instance can serve many domains, each one defined as a VirtualHost entry in
490 Prosody's configuration. Conversely a server that hosts a single domain would
491 have just one VirtualHost entry.
493 See @url{https://prosody.im/doc/configure#virtual_host_settings}."
497 (int-component-configuration-list '())
498 "Components are extra services on a server which are available to clients,
499 usually on a subdomain of the main server (such as
500 @samp{\"mycomponent.example.com\"}). Example components might be chatroom
501 servers, user directories, or gateways to other protocols.
503 Internal components are implemented with Prosody-specific plugins. To add an
504 internal component, you simply fill the hostname field, and the plugin you wish
505 to use for the component.
507 See @url{https://prosody.im/doc/components}."
511 (ext-component-configuration-list '())
512 "External components use XEP-0114, which most standalone components
513 support. To add an external component, you simply fill the hostname field. See
514 @url{https://prosody.im/doc/components}."
518 (string (configuration-missing-field 'ext-component 'component-secret))
519 "Password which the component will use to log in."
523 (non-negative-integer-list '(5347))
524 "Port(s) Prosody listens on for component connections."
529 "Interface Prosody listens on for component connections."
533 (string (configuration-missing-field 'virtualhost 'domain))
534 "Domain you wish Prosody to serve."
538 (string (configuration-missing-field 'int-component 'hostname))
539 "Hostname of the component."
543 (string (configuration-missing-field 'int-component 'plugin))
544 "Plugin you wish to use for the component."
548 (maybe-mod-muc-configuration 'disabled)
549 "Multi-user chat (MUC) is Prosody's module for allowing you to create
550 hosted chatrooms/conferences for XMPP users.
552 General information on setting up and using multi-user chatrooms can be found
553 in the \"Chatrooms\" documentation (@url{https://prosody.im/doc/chatrooms}),
554 which you should read if you are new to XMPP chatrooms.
556 See also @url{https://prosody.im/doc/modules/mod_muc}."
560 (string (configuration-missing-field 'ext-component 'hostname))
561 "Hostname of the component."
565 (maybe-raw-content 'disabled)
566 "Raw content that will be added to the configuration file."
569 ;; Serialize Virtualhost line first.
570 (define (serialize-virtualhost-configuration config)
571 (define (rest? field)
572 (not (memq (configuration-field-name field)
574 (let ((domain (virtualhost-configuration-domain config))
575 (rest (filter rest? virtualhost-configuration-fields)))
577 #$(format #f "VirtualHost \"~a\"\n" domain)
578 #$(serialize-configuration config rest))))
580 ;; Serialize Component line first.
581 (define (serialize-int-component-configuration config)
582 (define (rest? field)
583 (not (memq (configuration-field-name field)
584 '(hostname plugin))))
585 (let ((hostname (int-component-configuration-hostname config))
586 (plugin (int-component-configuration-plugin config))
587 (rest (filter rest? int-component-configuration-fields)))
589 #$(format #f "Component \"~a\" \"~a\"\n" hostname plugin)
590 #$(serialize-configuration config rest))))
592 ;; Serialize Component line first.
593 (define (serialize-ext-component-configuration config)
594 (define (rest? field)
595 (not (memq (configuration-field-name field)
597 (let ((hostname (ext-component-configuration-hostname config))
598 (rest (filter rest? ext-component-configuration-fields)))
600 #$(format #f "Component \"~a\"\n" hostname)
601 #$(serialize-configuration config rest))))
603 ;; Serialize virtualhosts and components last.
604 (define (serialize-prosody-configuration config)
605 (define (rest? field)
606 (not (memq (configuration-field-name field)
607 '(virtualhosts int-components ext-components))))
609 #$(let ((rest (filter rest? prosody-configuration-fields)))
610 (serialize-configuration config rest))
611 #$(serialize-virtualhost-configuration-list
612 (prosody-configuration-virtualhosts config))
613 #$(serialize-int-component-configuration-list
614 (prosody-configuration-int-components config))
615 #$(serialize-ext-component-configuration-list
616 (prosody-configuration-ext-components config))))
618 (define-configuration opaque-prosody-configuration
621 "The prosody package.")
624 (string (configuration-missing-field 'opaque-prosody-configuration
626 "The contents of the @code{prosody.cfg.lua} to use."))
628 (define (prosody-shepherd-service config)
629 "Return a <shepherd-service> for Prosody with CONFIG."
630 (let* ((prosody (if (opaque-prosody-configuration? config)
631 (opaque-prosody-configuration-prosody config)
632 (prosody-configuration-prosody config)))
633 (prosodyctl-bin (file-append prosody "/bin/prosodyctl"))
634 (prosodyctl-action (lambda args
636 (zero? (system* #$prosodyctl-bin #$@args))))))
637 (list (shepherd-service
638 (documentation "Run the Prosody XMPP server")
639 (provision '(prosody xmpp-daemon))
640 (requirement '(networking syslogd user-processes))
641 (start (prosodyctl-action "start"))
642 (stop (prosodyctl-action "stop"))))))
644 (define %prosody-accounts
645 (list (user-group (name "prosody") (system? #t))
650 (comment "Prosody daemon user")
651 (home-directory "/var/empty")
652 (shell (file-append shadow "/sbin/nologin")))))
654 (define (prosody-activation config)
655 "Return the activation gexp for CONFIG."
656 (let* ((config-dir "/etc/prosody")
657 (default-certs-dir "/etc/prosody/certs")
658 (data-path (prosody-configuration-data-path config))
659 (pidfile-dir (dirname (prosody-configuration-pidfile config)))
660 (config-str (if (opaque-prosody-configuration? config)
661 (opaque-prosody-configuration-prosody.cfg.lua config)
663 (use-modules (ice-9 format))
664 #$(serialize-prosody-configuration config))))
665 (config-file (mixed-text-file "prosody.cfg.lua" config-str)))
667 (use-modules (guix build utils))
668 (define %user (getpw "prosody"))
670 (mkdir-p #$config-dir)
671 (chown #$config-dir (passwd:uid %user) (passwd:gid %user))
672 (copy-file #$config-file (string-append #$config-dir
675 (mkdir-p #$default-certs-dir)
676 (chown #$default-certs-dir (passwd:uid %user) (passwd:gid %user))
677 (chmod #$default-certs-dir #o750)
679 (mkdir-p #$data-path)
680 (chown #$data-path (passwd:uid %user) (passwd:gid %user))
681 (chmod #$data-path #o750)
683 (mkdir-p #$pidfile-dir)
684 (chown #$pidfile-dir (passwd:uid %user) (passwd:gid %user)))))
686 (define prosody-service-type
687 (service-type (name 'prosody)
689 (list (service-extension shepherd-root-service-type
690 prosody-shepherd-service)
691 (service-extension account-service-type
692 (const %prosody-accounts))
693 (service-extension activation-service-type
694 prosody-activation)))))
696 ;; A little helper to make it easier to document all those fields.
697 (define (generate-documentation)
698 (define documentation
699 `((prosody-configuration
700 ,prosody-configuration-fields
701 (ssl ssl-configuration)
702 (virtualhosts virtualhost-configuration)
703 (int-components int-component-configuration)
704 (ext-components ext-component-configuration))
705 (ssl-configuration ,ssl-configuration-fields)
706 (int-component-configuration ,int-component-configuration-fields
707 (mod-muc mod-muc-configuration))
708 (ext-component-configuration ,ext-component-configuration-fields)
709 (mod-muc-configuration ,mod-muc-configuration-fields)
710 (virtualhost-configuration ,virtualhost-configuration-fields)
711 (opaque-prosody-configuration ,opaque-prosody-configuration-fields)))
712 (define (generate configuration-name)
713 (match (assq-ref documentation configuration-name)
714 ((fields . sub-documentation)
715 (format #t "\nAvailable @code{~a} fields are:\n\n" configuration-name)
716 (when (memq configuration-name
717 '(virtualhost-configuration
718 int-component-configuration
719 ext-component-configuration))
720 (format #t "all these @code{prosody-configuration} fields: ~a, plus:\n"
721 (string-join (map (lambda (s)
722 (format #f "@code{~a}" s)) common-fields)
726 (let ((field-name (configuration-field-name f))
727 (field-type (configuration-field-type f))
728 (field-docs (string-trim-both
729 (configuration-field-documentation f)))
731 (configuration-field-default-value-thunk f)
733 (define (escape-chars str chars escape)
734 (with-output-to-string
736 (string-for-each (lambda (c)
737 (when (char-set-contains? chars c)
741 (define (show-default? val)
742 (or (string? val) (number? val) (boolean? val)
743 (and (list? val) (and-map show-default? val))))
744 (format #t "@deftypevr {@code{~a} parameter} ~a ~a\n~a\n"
745 configuration-name field-type field-name field-docs)
746 (when (show-default? default)
747 (format #t "Defaults to @samp{~a}.\n"
748 (escape-chars (format #f "~s" default)
749 (char-set #\@ #\{ #\})
751 (for-each generate (or (assq-ref sub-documentation field-name) '()))
752 (format #t "@end deftypevr\n\n")))
754 (not (string=? "" (configuration-field-documentation f))))
756 (generate 'prosody-configuration)
757 (format #t "It could be that you just want to get a @code{prosody.cfg.lua}
758 up and running. In that case, you can pass an
759 @code{opaque-prosody-configuration} record as the value of
760 @code{prosody-service-type}. As its name indicates, an opaque configuration
761 does not have easy reflective capabilities.")
762 (generate 'opaque-prosody-configuration)
763 (format #t "For example, if your @code{prosody.cfg.lua} is just the empty
764 string, you could instantiate a prosody service like this:
767 (service prosody-service-type
768 (opaque-prosody-configuration
769 (prosody.cfg.lua \"\")))
777 (define-record-type* <bitlbee-configuration>
778 bitlbee-configuration make-bitlbee-configuration
779 bitlbee-configuration?
780 (bitlbee bitlbee-configuration-bitlbee
782 (interface bitlbee-configuration-interface
783 (default "127.0.0.1"))
784 (port bitlbee-configuration-port
786 (extra-settings bitlbee-configuration-extra-settings
789 (define bitlbee-shepherd-service
791 (($ <bitlbee-configuration> bitlbee interface port extra-settings)
792 (let ((conf (plain-file "bitlbee.conf"
796 ConfigDir = /var/lib/bitlbee
797 DaemonInterface = " interface "
798 DaemonPort = " (number->string port) "
801 (with-imported-modules (source-module-closure
802 '((gnu build shepherd)
803 (gnu system file-systems)))
804 (list (shepherd-service
805 (provision '(bitlbee))
807 ;; Note: If networking is not up, then /etc/resolv.conf
808 ;; doesn't get mapped in the container, hence the dependency
810 (requirement '(user-processes networking))
812 (modules '((gnu build shepherd)
813 (gnu system file-systems)))
814 (start #~(make-forkexec-constructor/container
815 (list #$(file-append bitlbee "/sbin/bitlbee")
816 "-n" "-F" "-u" "bitlbee" "-c" #$conf)
818 #:pid-file "/var/run/bitlbee.pid"
819 #:mappings (list (file-system-mapping
820 (source "/var/lib/bitlbee")
823 (stop #~(make-kill-destructor)))))))))
825 (define %bitlbee-accounts
826 ;; User group and account to run BitlBee.
827 (list (user-group (name "bitlbee") (system? #t))
832 (comment "BitlBee daemon user")
833 (home-directory "/var/empty")
834 (shell (file-append shadow "/sbin/nologin")))))
836 (define %bitlbee-activation
837 ;; Activation gexp for BitlBee.
839 (use-modules (guix build utils))
841 ;; This directory is used to store OTR data.
842 (mkdir-p "/var/lib/bitlbee")
843 (let ((user (getpwnam "bitlbee")))
844 (chown "/var/lib/bitlbee"
845 (passwd:uid user) (passwd:gid user)))))
847 (define bitlbee-service-type
848 (service-type (name 'bitlbee)
850 (list (service-extension shepherd-root-service-type
851 bitlbee-shepherd-service)
852 (service-extension account-service-type
853 (const %bitlbee-accounts))
854 (service-extension activation-service-type
855 (const %bitlbee-activation))))
856 (default-value (bitlbee-configuration))
858 "Run @url{http://bitlbee.org,BitlBee}, a daemon that acts as
859 a gateway between IRC and chat networks.")))
861 (define* (bitlbee-service #:key (bitlbee bitlbee) ;deprecated
862 (interface "127.0.0.1") (port 6667)
864 "Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
865 acts as a gateway between IRC and chat networks.
867 The daemon will listen to the interface corresponding to the IP address
868 specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
869 local clients can connect, whereas @code{0.0.0.0} means that connections can
870 come from any networking interface.
872 In addition, @var{extra-settings} specifies a string to append to the
874 (service bitlbee-service-type
875 (bitlbee-configuration
877 (interface interface) (port port)
878 (extra-settings extra-settings))))