mail.scm 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015 Andy Wingo <wingo@igalia.com>
  3. ;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org>
  4. ;;; Copyright © 2017 Carlo Zancanaro <carlo@zancanaro.id.au>
  5. ;;; Copyright © 2017, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
  6. ;;; Copyright © 2019 Kristofer Buffington <kristoferbuffington@gmail.com>
  7. ;;; Copyright © 2020 Jonathan Brielmaier <jonathan.brielmaier@web.de>
  8. ;;;
  9. ;;; This file is part of GNU Guix.
  10. ;;;
  11. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  12. ;;; under the terms of the GNU General Public License as published by
  13. ;;; the Free Software Foundation; either version 3 of the License, or (at
  14. ;;; your option) any later version.
  15. ;;;
  16. ;;; GNU Guix is distributed in the hope that it will be useful, but
  17. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;;; GNU General Public License for more details.
  20. ;;;
  21. ;;; You should have received a copy of the GNU General Public License
  22. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  23. ;;;
  24. ;;; Some of the help text was taken from the default dovecot.conf files.
  25. (define-module (gnu services mail)
  26. #:use-module (gnu services)
  27. #:use-module (gnu services base)
  28. #:use-module (gnu services configuration)
  29. #:use-module (gnu services shepherd)
  30. #:use-module (gnu system pam)
  31. #:use-module (gnu system shadow)
  32. #:use-module (gnu packages mail)
  33. #:use-module (gnu packages admin)
  34. #:use-module (gnu packages dav)
  35. #:use-module (gnu packages tls)
  36. #:use-module (guix records)
  37. #:use-module (guix packages)
  38. #:use-module (guix gexp)
  39. #:use-module (ice-9 match)
  40. #:use-module (ice-9 format)
  41. #:use-module (srfi srfi-1)
  42. #:export (dovecot-service
  43. dovecot-service-type
  44. dovecot-configuration
  45. opaque-dovecot-configuration
  46. dict-configuration
  47. passdb-configuration
  48. userdb-configuration
  49. unix-listener-configuration
  50. fifo-listener-configuration
  51. inet-listener-configuration
  52. service-configuration
  53. protocol-configuration
  54. plugin-configuration
  55. mailbox-configuration
  56. namespace-configuration
  57. opensmtpd-configuration
  58. opensmtpd-configuration?
  59. opensmtpd-service-type
  60. %default-opensmtpd-config-file
  61. mail-aliases-service-type
  62. exim-configuration
  63. exim-configuration?
  64. exim-service-type
  65. %default-exim-config-file
  66. imap4d-configuration
  67. imap4d-configuration?
  68. imap4d-service-type
  69. %default-imap4d-config-file
  70. radicale-configuration
  71. radicale-configuration?
  72. radicale-service-type
  73. %default-radicale-config-file))
  74. ;;; Commentary:
  75. ;;;
  76. ;;; This module provides service definitions for the Dovecot POP3 and IMAP
  77. ;;; mail server.
  78. ;;;
  79. ;;; Code:
  80. (define (uglify-field-name field-name)
  81. (let ((str (symbol->string field-name)))
  82. (string-join (string-split (if (string-suffix? "?" str)
  83. (substring str 0 (1- (string-length str)))
  84. str)
  85. #\-)
  86. "_")))
  87. (define (serialize-field field-name val)
  88. (format #t "~a=~a\n" (uglify-field-name field-name) val))
  89. (define (serialize-string field-name val)
  90. (serialize-field field-name val))
  91. (define (space-separated-string-list? val)
  92. (and (list? val)
  93. (and-map (lambda (x)
  94. (and (string? x) (not (string-index x #\space))))
  95. val)))
  96. (define (serialize-space-separated-string-list field-name val)
  97. (match val
  98. (() #f)
  99. (_ (serialize-field field-name (string-join val " ")))))
  100. (define (comma-separated-string-list? val)
  101. (and (list? val)
  102. (and-map (lambda (x)
  103. (and (string? x) (not (string-index x #\,))))
  104. val)))
  105. (define (serialize-comma-separated-string-list field-name val)
  106. (serialize-field field-name (string-join val ",")))
  107. (define (file-name? val)
  108. (and (string? val)
  109. (string-prefix? "/" val)))
  110. (define (serialize-file-name field-name val)
  111. (serialize-string field-name val))
  112. (define (colon-separated-file-name-list? val)
  113. (and (list? val)
  114. ;; Trailing slashes not needed and not
  115. (and-map file-name? val)))
  116. (define (serialize-colon-separated-file-name-list field-name val)
  117. (serialize-field field-name (string-join val ":")))
  118. (define (serialize-boolean field-name val)
  119. (serialize-string field-name (if val "yes" "no")))
  120. (define (non-negative-integer? val)
  121. (and (exact-integer? val) (not (negative? val))))
  122. (define (serialize-non-negative-integer field-name val)
  123. (serialize-field field-name val))
  124. (define (hours? val) (non-negative-integer? val))
  125. (define (serialize-hours field-name val)
  126. (serialize-field field-name (format #f "~a hours" val)))
  127. (define (free-form-fields? val)
  128. (match val
  129. (() #t)
  130. ((((? symbol?) . (? string?)) . val) (free-form-fields? val))
  131. (_ #f)))
  132. (define (serialize-free-form-fields field-name val)
  133. (for-each (match-lambda ((k . v) (serialize-field k v))) val))
  134. (define (free-form-args? val)
  135. (match val
  136. (() #t)
  137. ((((? symbol?) . (? string?)) . val) (free-form-args? val))
  138. (_ #f)))
  139. (define (serialize-free-form-args field-name val)
  140. (serialize-field field-name
  141. (string-join
  142. (map (match-lambda ((k . v) (format #f "~a=~a" k v))) val)
  143. " ")))
  144. (define-configuration dict-configuration
  145. (entries
  146. (free-form-fields '())
  147. "A list of key-value pairs that this dict should hold."))
  148. (define (serialize-dict-configuration field-name val)
  149. (format #t "dict {\n")
  150. (serialize-configuration val dict-configuration-fields)
  151. (format #t "}\n"))
  152. (define-configuration passdb-configuration
  153. (driver
  154. (string "pam")
  155. "The driver that the passdb should use. Valid values include
  156. @samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
  157. @samp{static}.")
  158. (args
  159. (space-separated-string-list '())
  160. "Space separated list of arguments to the passdb driver."))
  161. (define (serialize-passdb-configuration field-name val)
  162. (format #t "passdb {\n")
  163. (serialize-configuration val passdb-configuration-fields)
  164. (format #t "}\n"))
  165. (define (passdb-configuration-list? val)
  166. (and (list? val) (and-map passdb-configuration? val)))
  167. (define (serialize-passdb-configuration-list field-name val)
  168. (for-each (lambda (val) (serialize-passdb-configuration field-name val)) val))
  169. (define-configuration userdb-configuration
  170. (driver
  171. (string "passwd")
  172. "The driver that the userdb should use. Valid values include
  173. @samp{passwd} and @samp{static}.")
  174. (args
  175. (space-separated-string-list '())
  176. "Space separated list of arguments to the userdb driver.")
  177. (override-fields
  178. (free-form-args '())
  179. "Override fields from passwd."))
  180. (define (serialize-userdb-configuration field-name val)
  181. (format #t "userdb {\n")
  182. (serialize-configuration val userdb-configuration-fields)
  183. (format #t "}\n"))
  184. (define (userdb-configuration-list? val)
  185. (and (list? val) (and-map userdb-configuration? val)))
  186. (define (serialize-userdb-configuration-list field-name val)
  187. (for-each (lambda (val) (serialize-userdb-configuration field-name val)) val))
  188. (define-configuration unix-listener-configuration
  189. (path
  190. (string (configuration-missing-field 'unix-listener 'path))
  191. "Path to the file, relative to @code{base-dir} field. This is also used as
  192. the section name.")
  193. (mode
  194. (string "0600")
  195. "The access mode for the socket.")
  196. (user
  197. (string "")
  198. "The user to own the the socket.")
  199. (group
  200. (string "")
  201. "The group to own the socket."))
  202. (define (serialize-unix-listener-configuration field-name val)
  203. (format #t "unix_listener ~a {\n" (unix-listener-configuration-path val))
  204. (serialize-configuration val (cdr unix-listener-configuration-fields))
  205. (format #t "}\n"))
  206. (define-configuration fifo-listener-configuration
  207. (path
  208. (string (configuration-missing-field 'fifo-listener 'path))
  209. "Path to the file, relative to @code{base-dir} field. This is also used as
  210. the section name.")
  211. (mode
  212. (string "0600")
  213. "The access mode for the socket.")
  214. (user
  215. (string "")
  216. "The user to own the the socket.")
  217. (group
  218. (string "")
  219. "The group to own the socket."))
  220. (define (serialize-fifo-listener-configuration field-name val)
  221. (format #t "fifo_listener ~a {\n" (fifo-listener-configuration-path val))
  222. (serialize-configuration val (cdr fifo-listener-configuration-fields))
  223. (format #t "}\n"))
  224. (define-configuration inet-listener-configuration
  225. (protocol
  226. (string (configuration-missing-field 'inet-listener 'protocol))
  227. "The protocol to listen for.")
  228. (address
  229. (string "")
  230. "The address on which to listen, or empty for all addresses.")
  231. (port
  232. (non-negative-integer
  233. (configuration-missing-field 'inet-listener 'port))
  234. "The port on which to listen.")
  235. (ssl?
  236. (boolean #t)
  237. "Whether to use SSL for this service; @samp{yes}, @samp{no}, or
  238. @samp{required}."))
  239. (define (serialize-inet-listener-configuration field-name val)
  240. (format #t "inet_listener ~a {\n" (inet-listener-configuration-protocol val))
  241. (serialize-configuration val (cdr inet-listener-configuration-fields))
  242. (format #t "}\n"))
  243. (define (listener-configuration? val)
  244. (or (unix-listener-configuration? val)
  245. (fifo-listener-configuration? val)
  246. (inet-listener-configuration? val)))
  247. (define (serialize-listener-configuration field-name val)
  248. (cond
  249. ((unix-listener-configuration? val)
  250. (serialize-unix-listener-configuration field-name val))
  251. ((fifo-listener-configuration? val)
  252. (serialize-fifo-listener-configuration field-name val))
  253. ((inet-listener-configuration? val)
  254. (serialize-inet-listener-configuration field-name val))
  255. (else (configuration-field-error field-name val))))
  256. (define (listener-configuration-list? val)
  257. (and (list? val) (and-map listener-configuration? val)))
  258. (define (serialize-listener-configuration-list field-name val)
  259. (for-each (lambda (val)
  260. (serialize-listener-configuration field-name val))
  261. val))
  262. (define-configuration service-configuration
  263. (kind
  264. (string (configuration-missing-field 'service 'kind))
  265. "The service kind. Valid values include @code{director},
  266. @code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
  267. @code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
  268. @code{tcpwrap}, @code{quota-warning}, or anything else.")
  269. (listeners
  270. (listener-configuration-list '())
  271. "Listeners for the service. A listener is either an
  272. @code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
  273. an @code{inet-listener-configuration}.")
  274. (client-limit
  275. (non-negative-integer 0)
  276. "Maximum number of simultaneous client connections per process. Once this
  277. number of connections is received, the next incoming connection will prompt
  278. Dovecot to spawn another process. If set to 0, @code{default-client-limit} is
  279. used instead.")
  280. (service-count
  281. (non-negative-integer 1)
  282. "Number of connections to handle before starting a new process.
  283. Typically the only useful values are 0 (unlimited) or 1. 1 is more
  284. secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.")
  285. (process-limit
  286. (non-negative-integer 0)
  287. "Maximum number of processes that can exist for this service. If set to 0,
  288. @code{default-process-limit} is used instead.")
  289. (process-min-avail
  290. (non-negative-integer 0)
  291. "Number of processes to always keep waiting for more connections.")
  292. ;; FIXME: Need to be able to take the default for this value from other
  293. ;; parts of the config.
  294. (vsz-limit
  295. (non-negative-integer #e256e6)
  296. "If you set @samp{service-count 0}, you probably need to grow
  297. this."))
  298. (define (serialize-service-configuration field-name val)
  299. (format #t "service ~a {\n" (service-configuration-kind val))
  300. (serialize-configuration val (cdr service-configuration-fields))
  301. (format #t "}\n"))
  302. (define (service-configuration-list? val)
  303. (and (list? val) (and-map service-configuration? val)))
  304. (define (serialize-service-configuration-list field-name val)
  305. (for-each (lambda (val)
  306. (serialize-service-configuration field-name val))
  307. val))
  308. (define-configuration protocol-configuration
  309. (name
  310. (string (configuration-missing-field 'protocol 'name))
  311. "The name of the protocol.")
  312. (auth-socket-path
  313. (string "/var/run/dovecot/auth-userdb")
  314. "UNIX socket path to master authentication server to find users.
  315. This is used by imap (for shared users) and lda.")
  316. (mail-plugins
  317. (space-separated-string-list '("$mail_plugins"))
  318. "Space separated list of plugins to load.")
  319. (mail-max-userip-connections
  320. (non-negative-integer 10)
  321. "Maximum number of IMAP connections allowed for a user from each IP
  322. address. NOTE: The username is compared case-sensitively.")
  323. (imap-metadata?
  324. (boolean #f)
  325. "Whether to enable the @code{IMAP METADATA} extension as defined in
  326. @uref{https://tools.ietf.org/html/rfc5464, RFC@tie{}5464}, which provides
  327. a means for clients to set and retrieve per-mailbox, per-user metadata
  328. and annotations over IMAP.
  329. If this is @samp{#t}, you must also specify a dictionary @i{via} the
  330. @code{mail-attribute-dict} setting.")
  331. (managesieve-notify-capability
  332. (space-separated-string-list '())
  333. "Which NOTIFY capabilities to report to clients that first connect to
  334. the ManageSieve service, before authentication. These may differ from the
  335. capabilities offered to authenticated users. If this field is left empty,
  336. report what the Sieve interpreter supports by default.")
  337. (managesieve-sieve-capability
  338. (space-separated-string-list '())
  339. "Which SIEVE capabilities to report to clients that first connect to
  340. the ManageSieve service, before authentication. These may differ from the
  341. capabilities offered to authenticated users. If this field is left empty,
  342. report what the Sieve interpreter supports by default."))
  343. (define (serialize-protocol-configuration field-name val)
  344. (format #t "protocol ~a {\n" (protocol-configuration-name val))
  345. (serialize-configuration val (cdr protocol-configuration-fields))
  346. (format #t "}\n"))
  347. (define (protocol-configuration-list? val)
  348. (and (list? val) (and-map protocol-configuration? val)))
  349. (define (serialize-protocol-configuration-list field-name val)
  350. (serialize-field 'protocols
  351. (string-join (map protocol-configuration-name val) " "))
  352. (for-each (lambda (val)
  353. (serialize-protocol-configuration field-name val))
  354. val))
  355. (define-configuration plugin-configuration
  356. (entries
  357. (free-form-fields '())
  358. "A list of key-value pairs that this dict should hold."))
  359. (define (serialize-plugin-configuration field-name val)
  360. (format #t "plugin {\n")
  361. (serialize-configuration val plugin-configuration-fields)
  362. (format #t "}\n"))
  363. (define-configuration mailbox-configuration
  364. (name
  365. (string (error "mailbox name is required"))
  366. "Name for this mailbox.")
  367. (auto
  368. (string "no")
  369. "@samp{create} will automatically create this mailbox.
  370. @samp{subscribe} will both create and subscribe to the mailbox.")
  371. (special-use
  372. (space-separated-string-list '())
  373. "List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
  374. Valid values are @code{\\All}, @code{\\Archive}, @code{\\Drafts},
  375. @code{\\Flagged}, @code{\\Junk}, @code{\\Sent}, and @code{\\Trash}."))
  376. (define (serialize-mailbox-configuration field-name val)
  377. (format #t "mailbox \"~a\" {\n" (mailbox-configuration-name val))
  378. (serialize-configuration val (cdr mailbox-configuration-fields))
  379. (format #t "}\n"))
  380. (define (mailbox-configuration-list? val)
  381. (and (list? val) (and-map mailbox-configuration? val)))
  382. (define (serialize-mailbox-configuration-list field-name val)
  383. (for-each (lambda (val)
  384. (serialize-mailbox-configuration field-name val))
  385. val))
  386. (define-configuration namespace-configuration
  387. (name
  388. (string (error "namespace name is required"))
  389. "Name for this namespace.")
  390. (type
  391. (string "private")
  392. "Namespace type: @samp{private}, @samp{shared} or @samp{public}.")
  393. (separator
  394. (string "")
  395. "Hierarchy separator to use. You should use the same separator for
  396. all namespaces or some clients get confused. @samp{/} is usually a good
  397. one. The default however depends on the underlying mail storage
  398. format.")
  399. (prefix
  400. (string "")
  401. "Prefix required to access this namespace. This needs to be
  402. different for all namespaces. For example @samp{Public/}.")
  403. (location
  404. (string "")
  405. "Physical location of the mailbox. This is in same format as
  406. mail_location, which is also the default for it.")
  407. (inbox?
  408. (boolean #f)
  409. "There can be only one INBOX, and this setting defines which
  410. namespace has it.")
  411. (hidden?
  412. (boolean #f)
  413. "If namespace is hidden, it's not advertised to clients via NAMESPACE
  414. extension. You'll most likely also want to set @samp{list? #f}. This is mostly
  415. useful when converting from another server with different namespaces
  416. which you want to deprecate but still keep working. For example you can
  417. create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
  418. and @samp{mail/}.")
  419. (list?
  420. (boolean #t)
  421. "Show the mailboxes under this namespace with LIST command. This
  422. makes the namespace visible for clients that don't support NAMESPACE
  423. extension. The special @code{children} value lists child mailboxes, but
  424. hides the namespace prefix.")
  425. (subscriptions?
  426. (boolean #t)
  427. "Namespace handles its own subscriptions. If set to @code{#f}, the
  428. parent namespace handles them. The empty prefix should always have this
  429. as @code{#t}.)")
  430. (mailboxes
  431. (mailbox-configuration-list '())
  432. "List of predefined mailboxes in this namespace."))
  433. (define (serialize-namespace-configuration field-name val)
  434. (format #t "namespace ~a {\n" (namespace-configuration-name val))
  435. (serialize-configuration val (cdr namespace-configuration-fields))
  436. (format #t "}\n"))
  437. (define (list-of-namespace-configuration? val)
  438. (and (list? val) (and-map namespace-configuration? val)))
  439. (define (serialize-list-of-namespace-configuration field-name val)
  440. (for-each (lambda (val)
  441. (serialize-namespace-configuration field-name val))
  442. val))
  443. (define-configuration dovecot-configuration
  444. (dovecot
  445. (package dovecot)
  446. "The dovecot package.")
  447. (listen
  448. (comma-separated-string-list '("*" "::"))
  449. "A list of IPs or hosts where to listen in for connections. @samp{*}
  450. listens in all IPv4 interfaces, @samp{::} listens in all IPv6
  451. interfaces. If you want to specify non-default ports or anything more
  452. complex, customize the address and port fields of the
  453. @samp{inet-listener} of the specific services you are interested in.")
  454. (dict
  455. (dict-configuration (dict-configuration))
  456. "Dict configuration, as created by the @code{dict-configuration}
  457. constructor.")
  458. (passdbs
  459. (passdb-configuration-list (list (passdb-configuration (driver "pam"))))
  460. "List of passdb configurations, each one created by the
  461. @code{passdb-configuration} constructor.")
  462. (userdbs
  463. (userdb-configuration-list (list (userdb-configuration (driver "passwd"))))
  464. "List of userdb configurations, each one created by the
  465. @code{userdb-configuration} constructor.")
  466. (plugin-configuration
  467. (plugin-configuration (plugin-configuration))
  468. "Plug-in configuration, created by the @code{plugin-configuration}
  469. constructor.")
  470. (namespaces
  471. (list-of-namespace-configuration
  472. (list
  473. (namespace-configuration
  474. (name "inbox")
  475. (prefix "")
  476. (inbox? #t)
  477. (mailboxes
  478. (list
  479. (mailbox-configuration (name "Drafts") (special-use '("\\Drafts")))
  480. (mailbox-configuration (name "Junk") (special-use '("\\Junk")))
  481. (mailbox-configuration (name "Trash") (special-use '("\\Trash")))
  482. (mailbox-configuration (name "Sent") (special-use '("\\Sent")))
  483. (mailbox-configuration (name "Sent Messages") (special-use '("\\Sent")))
  484. (mailbox-configuration (name "Drafts") (special-use '("\\Drafts"))))))))
  485. "List of namespaces. Each item in the list is created by the
  486. @code{namespace-configuration} constructor.")
  487. (base-dir
  488. (file-name "/var/run/dovecot/")
  489. "Base directory where to store runtime data.")
  490. (login-greeting
  491. (string "Dovecot ready.")
  492. "Greeting message for clients.")
  493. (login-trusted-networks
  494. (space-separated-string-list '())
  495. "List of trusted network ranges. Connections from these IPs are
  496. allowed to override their IP addresses and ports (for logging and for
  497. authentication checks). @samp{disable-plaintext-auth} is also ignored
  498. for these networks. Typically you'd specify your IMAP proxy servers
  499. here.")
  500. (login-access-sockets
  501. (space-separated-string-list '())
  502. "List of login access check sockets (e.g. tcpwrap).")
  503. (verbose-proctitle?
  504. (boolean #f)
  505. "Show more verbose process titles (in ps). Currently shows user name
  506. and IP address. Useful for seeing who are actually using the IMAP
  507. processes (e.g. shared mailboxes or if same uid is used for multiple
  508. accounts).")
  509. (shutdown-clients?
  510. (boolean #t)
  511. "Should all processes be killed when Dovecot master process shuts down.
  512. Setting this to @code{#f} means that Dovecot can be upgraded without
  513. forcing existing client connections to close (although that could also
  514. be a problem if the upgrade is e.g. because of a security fix).")
  515. (doveadm-worker-count
  516. (non-negative-integer 0)
  517. "If non-zero, run mail commands via this many connections to doveadm
  518. server, instead of running them directly in the same process.")
  519. (doveadm-socket-path
  520. (string "doveadm-server")
  521. "UNIX socket or host:port used for connecting to doveadm server.")
  522. (import-environment
  523. (space-separated-string-list '("TZ"))
  524. "List of environment variables that are preserved on Dovecot startup
  525. and passed down to all of its child processes. You can also give
  526. key=value pairs to always set specific settings.")
  527. ;;; Authentication processes
  528. (disable-plaintext-auth?
  529. (boolean #t)
  530. "Disable LOGIN command and all other plaintext authentications unless
  531. SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
  532. matches the local IP (i.e. you're connecting from the same computer),
  533. the connection is considered secure and plaintext authentication is
  534. allowed. See also ssl=required setting.")
  535. (auth-cache-size
  536. (non-negative-integer 0)
  537. "Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
  538. Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
  539. for caching to be used.")
  540. (auth-cache-ttl
  541. (string "1 hour")
  542. "Time to live for cached data. After TTL expires the cached record
  543. is no longer used, *except* if the main database lookup returns internal
  544. failure. We also try to handle password changes automatically: If
  545. user's previous authentication was successful, but this one wasn't, the
  546. cache isn't used. For now this works only with plaintext
  547. authentication.")
  548. (auth-cache-negative-ttl
  549. (string "1 hour")
  550. "TTL for negative hits (user not found, password mismatch).
  551. 0 disables caching them completely.")
  552. (auth-realms
  553. (space-separated-string-list '())
  554. "List of realms for SASL authentication mechanisms that need them.
  555. You can leave it empty if you don't want to support multiple realms.
  556. Many clients simply use the first one listed here, so keep the default
  557. realm first.")
  558. (auth-default-realm
  559. (string "")
  560. "Default realm/domain to use if none was specified. This is used for
  561. both SASL realms and appending @@domain to username in plaintext
  562. logins.")
  563. (auth-username-chars
  564. (string
  565. "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@")
  566. "List of allowed characters in username. If the user-given username
  567. contains a character not listed in here, the login automatically fails.
  568. This is just an extra check to make sure user can't exploit any
  569. potential quote escaping vulnerabilities with SQL/LDAP databases. If
  570. you want to allow all characters, set this value to empty.")
  571. (auth-username-translation
  572. (string "")
  573. "Username character translations before it's looked up from
  574. databases. The value contains series of from -> to characters. For
  575. example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
  576. translated to @samp{@@}.")
  577. (auth-username-format
  578. (string "%Lu")
  579. "Username formatting before it's looked up from databases. You can
  580. use the standard variables here, e.g. %Lu would lowercase the username,
  581. %n would drop away the domain if it was given, or @samp{%n-AT-%d} would
  582. change the @samp{@@} into @samp{-AT-}. This translation is done after
  583. @samp{auth-username-translation} changes.")
  584. (auth-master-user-separator
  585. (string "")
  586. "If you want to allow master users to log in by specifying the master
  587. username within the normal username string (i.e. not using SASL
  588. mechanism's support for it), you can specify the separator character
  589. here. The format is then <username><separator><master username>.
  590. UW-IMAP uses @samp{*} as the separator, so that could be a good
  591. choice.")
  592. (auth-anonymous-username
  593. (string "anonymous")
  594. "Username to use for users logging in with ANONYMOUS SASL
  595. mechanism.")
  596. (auth-worker-max-count
  597. (non-negative-integer 30)
  598. "Maximum number of dovecot-auth worker processes. They're used to
  599. execute blocking passdb and userdb queries (e.g. MySQL and PAM).
  600. They're automatically created and destroyed as needed.")
  601. (auth-gssapi-hostname
  602. (string "")
  603. "Host name to use in GSSAPI principal names. The default is to use
  604. the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
  605. allow all keytab entries.")
  606. (auth-krb5-keytab
  607. (string "")
  608. "Kerberos keytab to use for the GSSAPI mechanism. Will use the
  609. system default (usually /etc/krb5.keytab) if not specified. You may
  610. need to change the auth service to run as root to be able to read this
  611. file.")
  612. (auth-use-winbind?
  613. (boolean #f)
  614. "Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
  615. and @samp{ntlm-auth} helper.
  616. <doc/wiki/Authentication/Mechanisms/Winbind.txt>.")
  617. (auth-winbind-helper-path
  618. (file-name "/usr/bin/ntlm_auth")
  619. "Path for Samba's @samp{ntlm-auth} helper binary.")
  620. (auth-failure-delay
  621. (string "2 secs")
  622. "Time to delay before replying to failed authentications.")
  623. (auth-ssl-require-client-cert?
  624. (boolean #f)
  625. "Require a valid SSL client certificate or the authentication
  626. fails.")
  627. (auth-ssl-username-from-cert?
  628. (boolean #f)
  629. "Take the username from client's SSL certificate, using
  630. @code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
  631. CommonName.")
  632. (auth-mechanisms
  633. (space-separated-string-list '("plain"))
  634. "List of wanted authentication mechanisms. Supported mechanisms are:
  635. @samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
  636. @samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
  637. @samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
  638. @samp{disable-plaintext-auth} setting.")
  639. (director-servers
  640. (space-separated-string-list '())
  641. "List of IPs or hostnames to all director servers, including ourself.
  642. Ports can be specified as ip:port. The default port is the same as what
  643. director service's @samp{inet-listener} is using.")
  644. (director-mail-servers
  645. (space-separated-string-list '())
  646. "List of IPs or hostnames to all backend mail servers. Ranges are
  647. allowed too, like 10.0.0.10-10.0.0.30.")
  648. (director-user-expire
  649. (string "15 min")
  650. "How long to redirect users to a specific server after it no longer
  651. has any connections.")
  652. (director-username-hash
  653. (string "%Lu")
  654. "How the username is translated before being hashed. Useful values
  655. include %Ln if user can log in with or without @@domain, %Ld if mailboxes
  656. are shared within domain.")
  657. ;;; Log destination.
  658. (log-path
  659. (string "syslog")
  660. "Log file to use for error messages. @samp{syslog} logs to syslog,
  661. @samp{/dev/stderr} logs to stderr.")
  662. (info-log-path
  663. (string "")
  664. "Log file to use for informational messages. Defaults to
  665. @samp{log-path}.")
  666. (debug-log-path
  667. (string "")
  668. "Log file to use for debug messages. Defaults to
  669. @samp{info-log-path}.")
  670. (syslog-facility
  671. (string "mail")
  672. "Syslog facility to use if you're logging to syslog. Usually if you
  673. don't want to use @samp{mail}, you'll use local0..local7. Also other
  674. standard facilities are supported.")
  675. (auth-verbose?
  676. (boolean #f)
  677. "Log unsuccessful authentication attempts and the reasons why they
  678. failed.")
  679. (auth-verbose-passwords
  680. (string "no")
  681. "In case of password mismatches, log the attempted password. Valid
  682. values are no, plain and sha1. sha1 can be useful for detecting brute
  683. force password attempts vs. user simply trying the same password over
  684. and over again. You can also truncate the value to n chars by appending
  685. \":n\" (e.g. sha1:6).")
  686. (auth-debug?
  687. (boolean #f)
  688. "Even more verbose logging for debugging purposes. Shows for example
  689. SQL queries.")
  690. (auth-debug-passwords?
  691. (boolean #f)
  692. "In case of password mismatches, log the passwords and used scheme so
  693. the problem can be debugged. Enabling this also enables
  694. @samp{auth-debug}.")
  695. (mail-debug?
  696. (boolean #f)
  697. "Enable mail process debugging. This can help you figure out why
  698. Dovecot isn't finding your mails.")
  699. (verbose-ssl?
  700. (boolean #f)
  701. "Show protocol level SSL errors.")
  702. (log-timestamp
  703. (string "\"%b %d %H:%M:%S \"")
  704. "Prefix for each line written to log file. % codes are in
  705. strftime(3) format.")
  706. (login-log-format-elements
  707. (space-separated-string-list
  708. '("user=<%u>" "method=%m" "rip=%r" "lip=%l" "mpid=%e" "%c"))
  709. "List of elements we want to log. The elements which have a
  710. non-empty variable value are joined together to form a comma-separated
  711. string.")
  712. (login-log-format
  713. (string "%$: %s")
  714. "Login log format. %s contains @samp{login-log-format-elements}
  715. string, %$ contains the data we want to log.")
  716. (mail-log-prefix
  717. (string "\"%s(%u)<%{pid}><%{session}>: \"")
  718. "Log prefix for mail processes. See doc/wiki/Variables.txt for list
  719. of possible variables you can use.")
  720. (deliver-log-format
  721. (string "msgid=%m: %$")
  722. "Format to use for logging mail deliveries. You can use variables:
  723. @table @code
  724. @item %$
  725. Delivery status message (e.g. @samp{saved to INBOX})
  726. @item %m
  727. Message-ID
  728. @item %s
  729. Subject
  730. @item %f
  731. From address
  732. @item %p
  733. Physical size
  734. @item %w
  735. Virtual size.
  736. @end table")
  737. ;;; Mailbox locations and namespaces
  738. (mail-location
  739. (string "")
  740. "Location for users' mailboxes. The default is empty, which means
  741. that Dovecot tries to find the mailboxes automatically. This won't work
  742. if the user doesn't yet have any mail, so you should explicitly tell
  743. Dovecot the full location.
  744. If you're using mbox, giving a path to the INBOX
  745. file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
  746. where the other mailboxes are kept. This is called the \"root mail
  747. directory\", and it must be the first path given in the
  748. @samp{mail-location} setting.
  749. There are a few special variables you can use, eg.:
  750. @table @samp
  751. @item %u
  752. username
  753. @item %n
  754. user part in user@@domain, same as %u if there's no domain
  755. @item %d
  756. domain part in user@@domain, empty if there's no domain
  757. @item %h
  758. home director
  759. @end table
  760. See doc/wiki/Variables.txt for full list. Some examples:
  761. @table @samp
  762. @item maildir:~/Maildir
  763. @item mbox:~/mail:INBOX=/var/mail/%u
  764. @item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
  765. @end table")
  766. (mail-uid
  767. (string "")
  768. "System user and group used to access mails. If you use multiple,
  769. userdb can override these by returning uid or gid fields. You can use
  770. either numbers or names. <doc/wiki/UserIds.txt>.")
  771. (mail-gid
  772. (string "")
  773. "")
  774. (mail-privileged-group
  775. (string "")
  776. "Group to enable temporarily for privileged operations. Currently
  777. this is used only with INBOX when either its initial creation or
  778. dotlocking fails. Typically this is set to \"mail\" to give access to
  779. /var/mail.")
  780. (mail-access-groups
  781. (string "")
  782. "Grant access to these supplementary groups for mail processes.
  783. Typically these are used to set up access to shared mailboxes. Note
  784. that it may be dangerous to set these if users can create
  785. symlinks (e.g. if \"mail\" group is set here, ln -s /var/mail ~/mail/var
  786. could allow a user to delete others' mailboxes, or ln -s
  787. /secret/shared/box ~/mail/mybox would allow reading it).")
  788. (mail-full-filesystem-access?
  789. (boolean #f)
  790. "Allow full file system access to clients. There's no access checks
  791. other than what the operating system does for the active UID/GID. It
  792. works with both maildir and mboxes, allowing you to prefix mailboxes
  793. names with e.g. /path/ or ~user/.")
  794. ;;; Mail processes
  795. (mmap-disable?
  796. (boolean #f)
  797. "Don't use mmap() at all. This is required if you store indexes to
  798. shared file systems (NFS or clustered file system).")
  799. (dotlock-use-excl?
  800. (boolean #t)
  801. "Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
  802. supports @samp{O_EXCL} since version 3, so this should be safe to use
  803. nowadays by default.")
  804. (mail-fsync
  805. (string "optimized")
  806. "When to use fsync() or fdatasync() calls:
  807. @table @code
  808. @item optimized
  809. Whenever necessary to avoid losing important data
  810. @item always
  811. Useful with e.g. NFS when write()s are delayed
  812. @item never
  813. Never use it (best performance, but crashes can lose data).
  814. @end table")
  815. (mail-nfs-storage?
  816. (boolean #f)
  817. "Mail storage exists in NFS. Set this to yes to make Dovecot flush
  818. NFS caches whenever needed. If you're using only a single mail server
  819. this isn't needed.")
  820. (mail-nfs-index?
  821. (boolean #f)
  822. "Mail index files also exist in NFS. Setting this to yes requires
  823. @samp{mmap-disable? #t} and @samp{fsync-disable? #f}.")
  824. (lock-method
  825. (string "fcntl")
  826. "Locking method for index files. Alternatives are fcntl, flock and
  827. dotlock. Dotlocking uses some tricks which may create more disk I/O
  828. than other locking methods. NFS users: flock doesn't work, remember to
  829. change @samp{mmap-disable}.")
  830. (mail-temp-dir
  831. (file-name "/tmp")
  832. "Directory in which LDA/LMTP temporarily stores incoming mails >128
  833. kB.")
  834. (first-valid-uid
  835. (non-negative-integer 500)
  836. "Valid UID range for users. This is mostly to make sure that users can't
  837. log in as daemons or other system users. Note that denying root logins is
  838. hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
  839. is set to 0.")
  840. (last-valid-uid
  841. (non-negative-integer 0)
  842. "")
  843. (first-valid-gid
  844. (non-negative-integer 1)
  845. "Valid GID range for users. Users having non-valid GID as primary group ID
  846. aren't allowed to log in. If user belongs to supplementary groups with
  847. non-valid GIDs, those groups are not set.")
  848. (last-valid-gid
  849. (non-negative-integer 0)
  850. "")
  851. (mail-max-keyword-length
  852. (non-negative-integer 50)
  853. "Maximum allowed length for mail keyword name. It's only forced when
  854. trying to create new keywords.")
  855. (valid-chroot-dirs
  856. (colon-separated-file-name-list '())
  857. "List of directories under which chrooting is allowed for mail
  858. processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
  859. too). This setting doesn't affect @samp{login-chroot}
  860. @samp{mail-chroot} or auth chroot settings. If this setting is empty,
  861. \"/./\" in home dirs are ignored. WARNING: Never add directories here
  862. which local users can modify, that may lead to root exploit. Usually
  863. this should be done only if you don't allow shell access for users.
  864. <doc/wiki/Chrooting.txt>.")
  865. (mail-chroot
  866. (string "")
  867. "Default chroot directory for mail processes. This can be overridden
  868. for specific users in user database by giving /./ in user's home
  869. directory (e.g. /home/./user chroots into /home). Note that usually
  870. there is no real need to do chrooting, Dovecot doesn't allow users to
  871. access files outside their mail directory anyway. If your home
  872. directories are prefixed with the chroot directory, append \"/.\" to
  873. @samp{mail-chroot}. <doc/wiki/Chrooting.txt>.")
  874. (auth-socket-path
  875. (file-name "/var/run/dovecot/auth-userdb")
  876. "UNIX socket path to master authentication server to find users.
  877. This is used by imap (for shared users) and lda.")
  878. (mail-plugin-dir
  879. (file-name "/usr/lib/dovecot")
  880. "Directory where to look up mail plugins.")
  881. (mail-plugins
  882. (space-separated-string-list '())
  883. "List of plugins to load for all services. Plugins specific to IMAP,
  884. LDA, etc. are added to this list in their own .conf files.")
  885. (mail-cache-min-mail-count
  886. (non-negative-integer 0)
  887. "The minimum number of mails in a mailbox before updates are done to
  888. cache file. This allows optimizing Dovecot's behavior to do less disk
  889. writes at the cost of more disk reads.")
  890. (mailbox-idle-check-interval
  891. (string "30 secs")
  892. "When IDLE command is running, mailbox is checked once in a while to
  893. see if there are any new mails or other changes. This setting defines
  894. the minimum time to wait between those checks. Dovecot can also use
  895. dnotify, inotify and kqueue to find out immediately when changes
  896. occur.")
  897. (mail-save-crlf?
  898. (boolean #f)
  899. "Save mails with CR+LF instead of plain LF. This makes sending those
  900. mails take less CPU, especially with sendfile() syscall with Linux and
  901. FreeBSD. But it also creates a bit more disk I/O which may just make it
  902. slower. Also note that if other software reads the mboxes/maildirs,
  903. they may handle the extra CRs wrong and cause problems.")
  904. (maildir-stat-dirs?
  905. (boolean #f)
  906. "By default LIST command returns all entries in maildir beginning
  907. with a dot. Enabling this option makes Dovecot return only entries
  908. which are directories. This is done by stat()ing each entry, so it
  909. causes more disk I/O.
  910. (For systems setting struct @samp{dirent->d_type} this check is free
  911. and it's done always regardless of this setting).")
  912. (maildir-copy-with-hardlinks?
  913. (boolean #t)
  914. "When copying a message, do it with hard links whenever possible.
  915. This makes the performance much better, and it's unlikely to have any
  916. side effects.")
  917. (maildir-very-dirty-syncs?
  918. (boolean #f)
  919. "Assume Dovecot is the only MUA accessing Maildir: Scan cur/
  920. directory only when its mtime changes unexpectedly or when we can't find
  921. the mail otherwise.")
  922. (mbox-read-locks
  923. (space-separated-string-list '("fcntl"))
  924. "Which locking methods to use for locking mbox. There are four
  925. available:
  926. @table @code
  927. @item dotlock
  928. Create <mailbox>.lock file. This is the oldest and most NFS-safe
  929. solution. If you want to use /var/mail/ like directory, the users will
  930. need write access to that directory.
  931. @item dotlock-try
  932. Same as dotlock, but if it fails because of permissions or because there
  933. isn't enough disk space, just skip it.
  934. @item fcntl
  935. Use this if possible. Works with NFS too if lockd is used.
  936. @item flock
  937. May not exist in all systems. Doesn't work with NFS.
  938. @item lockf
  939. May not exist in all systems. Doesn't work with NFS.
  940. @end table
  941. You can use multiple locking methods; if you do the order they're declared
  942. in is important to avoid deadlocks if other MTAs/MUAs are using multiple
  943. locking methods as well. Some operating systems don't allow using some of
  944. them simultaneously.")
  945. (mbox-write-locks
  946. (space-separated-string-list '("dotlock" "fcntl"))
  947. "")
  948. (mbox-lock-timeout
  949. (string "5 mins")
  950. "Maximum time to wait for lock (all of them) before aborting.")
  951. (mbox-dotlock-change-timeout
  952. (string "2 mins")
  953. "If dotlock exists but the mailbox isn't modified in any way,
  954. override the lock file after this much time.")
  955. (mbox-dirty-syncs?
  956. (boolean #t)
  957. "When mbox changes unexpectedly we have to fully read it to find out
  958. what changed. If the mbox is large this can take a long time. Since
  959. the change is usually just a newly appended mail, it'd be faster to
  960. simply read the new mails. If this setting is enabled, Dovecot does
  961. this but still safely fallbacks to re-reading the whole mbox file
  962. whenever something in mbox isn't how it's expected to be. The only real
  963. downside to this setting is that if some other MUA changes message
  964. flags, Dovecot doesn't notice it immediately. Note that a full sync is
  965. done with SELECT, EXAMINE, EXPUNGE and CHECK commands.")
  966. (mbox-very-dirty-syncs?
  967. (boolean #f)
  968. "Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
  969. EXAMINE, EXPUNGE or CHECK commands. If this is set,
  970. @samp{mbox-dirty-syncs} is ignored.")
  971. (mbox-lazy-writes?
  972. (boolean #t)
  973. "Delay writing mbox headers until doing a full write sync (EXPUNGE
  974. and CHECK commands and when closing the mailbox). This is especially
  975. useful for POP3 where clients often delete all mails. The downside is
  976. that our changes aren't immediately visible to other MUAs.")
  977. (mbox-min-index-size
  978. (non-negative-integer 0)
  979. "If mbox size is smaller than this (e.g. 100k), don't write index
  980. files. If an index file already exists it's still read, just not
  981. updated.")
  982. (mdbox-rotate-size
  983. (non-negative-integer #e10e6)
  984. "Maximum dbox file size until it's rotated.")
  985. (mdbox-rotate-interval
  986. (string "1d")
  987. "Maximum dbox file age until it's rotated. Typically in days. Day
  988. begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
  989. disabled.")
  990. (mdbox-preallocate-space?
  991. (boolean #f)
  992. "When creating new mdbox files, immediately preallocate their size to
  993. @samp{mdbox-rotate-size}. This setting currently works only in Linux
  994. with some file systems (ext4, xfs).")
  995. (mail-attribute-dict
  996. (string "")
  997. "The location of a dictionary used to store @code{IMAP METADATA}
  998. as defined by @uref{https://tools.ietf.org/html/rfc5464, RFC@tie{}5464}.
  999. The IMAP METADATA commands are available only if the ``imap''
  1000. protocol configuration's @code{imap-metadata?} field is @samp{#t}.")
  1001. (mail-attachment-dir
  1002. (string "")
  1003. "sdbox and mdbox support saving mail attachments to external files,
  1004. which also allows single instance storage for them. Other backends
  1005. don't support this for now.
  1006. WARNING: This feature hasn't been tested much yet. Use at your own risk.
  1007. Directory root where to store mail attachments. Disabled, if empty.")
  1008. (mail-attachment-min-size
  1009. (non-negative-integer #e128e3)
  1010. "Attachments smaller than this aren't saved externally. It's also
  1011. possible to write a plugin to disable saving specific attachments
  1012. externally.")
  1013. (mail-attachment-fs
  1014. (string "sis posix")
  1015. "File system backend to use for saving attachments:
  1016. @table @code
  1017. @item posix
  1018. No SiS done by Dovecot (but this might help FS's own deduplication)
  1019. @item sis posix
  1020. SiS with immediate byte-by-byte comparison during saving
  1021. @item sis-queue posix
  1022. SiS with delayed comparison and deduplication.
  1023. @end table")
  1024. (mail-attachment-hash
  1025. (string "%{sha1}")
  1026. "Hash format to use in attachment filenames. You can add any text and
  1027. variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
  1028. @code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
  1029. truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.")
  1030. (default-process-limit
  1031. (non-negative-integer 100)
  1032. "")
  1033. (default-client-limit
  1034. (non-negative-integer 1000)
  1035. "")
  1036. (default-vsz-limit
  1037. (non-negative-integer #e256e6)
  1038. "Default VSZ (virtual memory size) limit for service processes.
  1039. This is mainly intended to catch and kill processes that leak memory
  1040. before they eat up everything.")
  1041. (default-login-user
  1042. (string "dovenull")
  1043. "Login user is internally used by login processes. This is the most
  1044. untrusted user in Dovecot system. It shouldn't have access to anything
  1045. at all.")
  1046. (default-internal-user
  1047. (string "dovecot")
  1048. "Internal user is used by unprivileged processes. It should be
  1049. separate from login user, so that login processes can't disturb other
  1050. processes.")
  1051. (ssl?
  1052. (string "required")
  1053. "SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.")
  1054. (ssl-cert
  1055. (string "</etc/dovecot/default.pem")
  1056. "PEM encoded X.509 SSL/TLS certificate (public key).")
  1057. (ssl-key
  1058. (string "</etc/dovecot/private/default.pem")
  1059. "PEM encoded SSL/TLS private key. The key is opened before
  1060. dropping root privileges, so keep the key file unreadable by anyone but
  1061. root.")
  1062. (ssl-key-password
  1063. (string "")
  1064. "If key file is password protected, give the password here.
  1065. Alternatively give it when starting dovecot with -p parameter. Since
  1066. this file is often world-readable, you may want to place this setting
  1067. instead to a different.")
  1068. (ssl-ca
  1069. (string "")
  1070. "PEM encoded trusted certificate authority. Set this only if you
  1071. intend to use @samp{ssl-verify-client-cert? #t}. The file should
  1072. contain the CA certificate(s) followed by the matching
  1073. CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).")
  1074. (ssl-require-crl?
  1075. (boolean #t)
  1076. "Require that CRL check succeeds for client certificates.")
  1077. (ssl-verify-client-cert?
  1078. (boolean #f)
  1079. "Request client to send a certificate. If you also want to require
  1080. it, set @samp{auth-ssl-require-client-cert? #t} in auth section.")
  1081. (ssl-cert-username-field
  1082. (string "commonName")
  1083. "Which field from certificate to use for username. commonName and
  1084. x500UniqueIdentifier are the usual choices. You'll also need to set
  1085. @samp{auth-ssl-username-from-cert? #t}.")
  1086. (ssl-min-protocol
  1087. (string "TLSv1")
  1088. "Minimum SSL protocol version to accept.")
  1089. (ssl-cipher-list
  1090. (string "ALL:!kRSA:!SRP:!kDHd:!DSS:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK:!RC4:!ADH:!LOW@STRENGTH")
  1091. "SSL ciphers to use.")
  1092. (ssl-crypto-device
  1093. (string "")
  1094. "SSL crypto device to use, for valid values run \"openssl engine\".")
  1095. (postmaster-address
  1096. (string "postmaster@%d")
  1097. "Address to use when sending rejection mails.
  1098. Default is postmaster@@<your domain>. %d expands to recipient domain.")
  1099. (hostname
  1100. (string "")
  1101. "Hostname to use in various parts of sent mails (e.g. in Message-Id)
  1102. and in LMTP replies. Default is the system's real hostname@@domain.")
  1103. (quota-full-tempfail?
  1104. (boolean #f)
  1105. "If user is over quota, return with temporary failure instead of
  1106. bouncing the mail.")
  1107. (sendmail-path
  1108. (file-name "/usr/sbin/sendmail")
  1109. "Binary to use for sending mails.")
  1110. (submission-host
  1111. (string "")
  1112. "If non-empty, send mails via this SMTP host[:port] instead of
  1113. sendmail.")
  1114. (rejection-subject
  1115. (string "Rejected: %s")
  1116. "Subject: header to use for rejection mails. You can use the same
  1117. variables as for @samp{rejection-reason} below.")
  1118. (rejection-reason
  1119. (string "Your message to <%t> was automatically rejected:%n%r")
  1120. "Human readable error message for rejection mails. You can use
  1121. variables:
  1122. @table @code
  1123. @item %n
  1124. CRLF
  1125. @item %r
  1126. reason
  1127. @item %s
  1128. original subject
  1129. @item %t
  1130. recipient
  1131. @end table")
  1132. (recipient-delimiter
  1133. (string "+")
  1134. "Delimiter character between local-part and detail in email
  1135. address.")
  1136. (lda-original-recipient-header
  1137. (string "")
  1138. "Header where the original recipient address (SMTP's RCPT TO:
  1139. address) is taken from if not available elsewhere. With dovecot-lda -a
  1140. parameter overrides this. A commonly used header for this is
  1141. X-Original-To.")
  1142. (lda-mailbox-autocreate?
  1143. (boolean #f)
  1144. "Should saving a mail to a nonexistent mailbox automatically create
  1145. it?.")
  1146. (lda-mailbox-autosubscribe?
  1147. (boolean #f)
  1148. "Should automatically created mailboxes be also automatically
  1149. subscribed?.")
  1150. (imap-max-line-length
  1151. (non-negative-integer #e64e3)
  1152. "Maximum IMAP command line length. Some clients generate very long
  1153. command lines with huge mailboxes, so you may need to raise this if you
  1154. get \"Too long argument\" or \"IMAP command line too large\" errors
  1155. often.")
  1156. (imap-logout-format
  1157. (string "in=%i out=%o deleted=%{deleted} expunged=%{expunged} trashed=%{trashed} hdr_count=%{fetch_hdr_count} hdr_bytes=%{fetch_hdr_bytes} body_count=%{fetch_body_count} body_bytes=%{fetch_body_bytes}")
  1158. "IMAP logout format string:
  1159. @table @code
  1160. @item %i
  1161. total number of bytes read from client
  1162. @item %o
  1163. total number of bytes sent to client.
  1164. @end table
  1165. See @file{doc/wiki/Variables.txt} for a list of all the variables you can use.")
  1166. (imap-capability
  1167. (string "")
  1168. "Override the IMAP CAPABILITY response. If the value begins with '+',
  1169. add the given capabilities on top of the defaults (e.g. +XFOO XBAR).")
  1170. (imap-idle-notify-interval
  1171. (string "2 mins")
  1172. "How long to wait between \"OK Still here\" notifications when client
  1173. is IDLEing.")
  1174. (imap-id-send
  1175. (string "")
  1176. "ID field names and values to send to clients. Using * as the value
  1177. makes Dovecot use the default value. The following fields have default
  1178. values currently: name, version, os, os-version, support-url,
  1179. support-email.")
  1180. (imap-id-log
  1181. (string "")
  1182. "ID fields sent by client to log. * means everything.")
  1183. (imap-client-workarounds
  1184. (space-separated-string-list '())
  1185. "Workarounds for various client bugs:
  1186. @table @code
  1187. @item delay-newmail
  1188. Send EXISTS/RECENT new mail notifications only when replying to NOOP and
  1189. CHECK commands. Some clients ignore them otherwise, for example OSX
  1190. Mail (<v2.1). Outlook Express breaks more badly though, without this it
  1191. may show user \"Message no longer in server\" errors. Note that OE6
  1192. still breaks even with this workaround if synchronization is set to
  1193. \"Headers Only\".
  1194. @item tb-extra-mailbox-sep
  1195. Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
  1196. adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
  1197. ignore the extra @samp{/} instead of treating it as invalid mailbox name.
  1198. @item tb-lsub-flags
  1199. Show \\Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
  1200. This makes Thunderbird realize they aren't selectable and show them
  1201. greyed out, instead of only later giving \"not selectable\" popup error.
  1202. @end table
  1203. ")
  1204. (imap-urlauth-host
  1205. (string "")
  1206. "Host allowed in URLAUTH URLs sent by client. \"*\" allows all.")
  1207. (protocols
  1208. (protocol-configuration-list
  1209. (list (protocol-configuration
  1210. (name "imap"))))
  1211. "List of protocols we want to serve. Available protocols include
  1212. @samp{imap}, @samp{pop3}, and @samp{lmtp}.")
  1213. (services
  1214. (service-configuration-list
  1215. (list
  1216. (service-configuration
  1217. (kind "imap-login")
  1218. (client-limit 0)
  1219. (process-limit 0)
  1220. (listeners
  1221. (list
  1222. (inet-listener-configuration (protocol "imap") (port 143) (ssl? #f))
  1223. (inet-listener-configuration (protocol "imaps") (port 993) (ssl? #t)))))
  1224. (service-configuration
  1225. (kind "pop3-login")
  1226. (listeners
  1227. (list
  1228. (inet-listener-configuration (protocol "pop3") (port 110) (ssl? #f))
  1229. (inet-listener-configuration (protocol "pop3s") (port 995) (ssl? #t)))))
  1230. (service-configuration
  1231. (kind "lmtp")
  1232. (client-limit 1)
  1233. (process-limit 0)
  1234. (listeners
  1235. (list (unix-listener-configuration (path "lmtp") (mode "0666")))))
  1236. (service-configuration
  1237. (kind "imap")
  1238. (client-limit 1)
  1239. (process-limit 1024))
  1240. (service-configuration
  1241. (kind "pop3")
  1242. (client-limit 1)
  1243. (process-limit 1024))
  1244. (service-configuration
  1245. (kind "auth")
  1246. (service-count 0)
  1247. (client-limit 0)
  1248. (process-limit 1)
  1249. (listeners
  1250. (list (unix-listener-configuration (path "auth-userdb")))))
  1251. (service-configuration
  1252. (kind "auth-worker")
  1253. (client-limit 1)
  1254. (process-limit 0))
  1255. (service-configuration
  1256. (kind "dict")
  1257. (client-limit 1)
  1258. (process-limit 0)
  1259. (listeners (list (unix-listener-configuration (path "dict")))))))
  1260. "List of services to enable. Available services include @samp{imap},
  1261. @samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
  1262. @samp{lmtp}."))
  1263. (define-configuration opaque-dovecot-configuration
  1264. (dovecot
  1265. (package dovecot)
  1266. "The dovecot package.")
  1267. (string
  1268. (string (configuration-missing-field 'opaque-dovecot-configuration
  1269. 'string))
  1270. "The contents of the @code{dovecot.conf} to use."))
  1271. (define %dovecot-accounts
  1272. ;; Account and group for the Dovecot daemon.
  1273. (list (user-group (name "dovecot") (system? #t))
  1274. (user-account
  1275. (name "dovecot")
  1276. (group "dovecot")
  1277. (system? #t)
  1278. (comment "Dovecot daemon user")
  1279. (home-directory "/var/empty")
  1280. (shell (file-append shadow "/sbin/nologin")))
  1281. (user-group (name "dovenull") (system? #t))
  1282. (user-account
  1283. (name "dovenull")
  1284. (group "dovenull")
  1285. (system? #t)
  1286. (comment "Dovecot daemon login user")
  1287. (home-directory "/var/empty")
  1288. (shell (file-append shadow "/sbin/nologin")))))
  1289. (define (%dovecot-activation config)
  1290. ;; Activation gexp.
  1291. (let ((config-str
  1292. (cond
  1293. ((opaque-dovecot-configuration? config)
  1294. (opaque-dovecot-configuration-string config))
  1295. (else
  1296. (with-output-to-string
  1297. (lambda ()
  1298. (serialize-configuration config
  1299. dovecot-configuration-fields)))))))
  1300. #~(begin
  1301. (use-modules (guix build utils))
  1302. (define (mkdir-p/perms directory owner perms)
  1303. (mkdir-p directory)
  1304. (chown "/var/run/dovecot" (passwd:uid owner) (passwd:gid owner))
  1305. (chmod directory perms))
  1306. (define (build-subject parameters)
  1307. (string-concatenate
  1308. (map (lambda (pair)
  1309. (let ((k (car pair)) (v (cdr pair)))
  1310. (define (escape-char str chr)
  1311. (string-join (string-split str chr) (string #\\ chr)))
  1312. (string-append "/" k "="
  1313. (escape-char (escape-char v #\=) #\/))))
  1314. (filter (lambda (pair) (cdr pair)) parameters))))
  1315. (define* (create-self-signed-certificate-if-absent
  1316. #:key private-key public-key (owner (getpwnam "root"))
  1317. (common-name (gethostname))
  1318. (organization-name "Guix")
  1319. (organization-unit-name "Default Self-Signed Certificate")
  1320. (subject-parameters `(("CN" . ,common-name)
  1321. ("O" . ,organization-name)
  1322. ("OU" . ,organization-unit-name)))
  1323. (subject (build-subject subject-parameters)))
  1324. ;; Note that by default, OpenSSL outputs keys in PEM format. This
  1325. ;; is what we want.
  1326. (unless (file-exists? private-key)
  1327. (cond
  1328. ((zero? (system* (string-append #$openssl "/bin/openssl")
  1329. "genrsa" "-out" private-key "2048"))
  1330. (chown private-key (passwd:uid owner) (passwd:gid owner))
  1331. (chmod private-key #o400))
  1332. (else
  1333. (format (current-error-port)
  1334. "Failed to create private key at ~a.\n" private-key))))
  1335. (unless (file-exists? public-key)
  1336. (cond
  1337. ((zero? (system* (string-append #$openssl "/bin/openssl")
  1338. "req" "-new" "-x509" "-key" private-key
  1339. "-out" public-key "-days" "3650"
  1340. "-batch" "-subj" subject))
  1341. (chown public-key (passwd:uid owner) (passwd:gid owner))
  1342. (chmod public-key #o444))
  1343. (else
  1344. (format (current-error-port)
  1345. "Failed to create public key at ~a.\n" public-key)))))
  1346. (let ((user (getpwnam "dovecot")))
  1347. (mkdir-p/perms "/var/run/dovecot" user #o755)
  1348. (mkdir-p/perms "/var/lib/dovecot" user #o755)
  1349. (mkdir-p/perms "/etc/dovecot" user #o755)
  1350. (copy-file #$(plain-file "dovecot.conf" config-str)
  1351. "/etc/dovecot/dovecot.conf")
  1352. (mkdir-p/perms "/etc/dovecot/private" user #o700)
  1353. (create-self-signed-certificate-if-absent
  1354. #:private-key "/etc/dovecot/private/default.pem"
  1355. #:public-key "/etc/dovecot/default.pem"
  1356. #:owner (getpwnam "root")
  1357. #:common-name (format #f "Dovecot service on ~a" (gethostname)))))))
  1358. (define (dovecot-shepherd-service config)
  1359. "Return a list of <shepherd-service> for CONFIG."
  1360. (let ((dovecot (if (opaque-dovecot-configuration? config)
  1361. (opaque-dovecot-configuration-dovecot config)
  1362. (dovecot-configuration-dovecot config))))
  1363. (list (shepherd-service
  1364. (documentation "Run the Dovecot POP3/IMAP mail server.")
  1365. (provision '(dovecot))
  1366. (requirement '(networking))
  1367. (start #~(make-forkexec-constructor
  1368. (list (string-append #$dovecot "/sbin/dovecot")
  1369. "-F")))
  1370. (stop #~(lambda _
  1371. (invoke #$(file-append dovecot "/sbin/dovecot")
  1372. "stop")
  1373. #f))))))
  1374. (define %dovecot-pam-services
  1375. (list (unix-pam-service "dovecot")))
  1376. (define dovecot-service-type
  1377. (service-type (name 'dovecot)
  1378. (extensions
  1379. (list (service-extension shepherd-root-service-type
  1380. dovecot-shepherd-service)
  1381. (service-extension account-service-type
  1382. (const %dovecot-accounts))
  1383. (service-extension pam-root-service-type
  1384. (const %dovecot-pam-services))
  1385. (service-extension activation-service-type
  1386. %dovecot-activation)))))
  1387. (define* (dovecot-service #:key (config (dovecot-configuration)))
  1388. "Return a service that runs @command{dovecot}, a mail server that can run
  1389. POP3, IMAP, and LMTP. @var{config} should be a configuration object created
  1390. by @code{dovecot-configuration}. @var{config} may also be created by
  1391. @code{opaque-dovecot-configuration}, which allows specification of the
  1392. @code{dovecot.conf} as a string."
  1393. (validate-configuration config
  1394. (if (opaque-dovecot-configuration? config)
  1395. opaque-dovecot-configuration-fields
  1396. dovecot-configuration-fields))
  1397. (service dovecot-service-type config))
  1398. ;; A little helper to make it easier to document all those fields.
  1399. (define (generate-dovecot-documentation)
  1400. (generate-documentation
  1401. `((dovecot-configuration
  1402. ,dovecot-configuration-fields
  1403. (dict dict-configuration)
  1404. (namespaces namespace-configuration)
  1405. (plugin plugin-configuration)
  1406. (passdbs passdb-configuration)
  1407. (userdbs userdb-configuration)
  1408. (services service-configuration)
  1409. (protocols protocol-configuration))
  1410. (dict-configuration ,dict-configuration-fields)
  1411. (plugin-configuration ,plugin-configuration-fields)
  1412. (passdb-configuration ,passdb-configuration-fields)
  1413. (userdb-configuration ,userdb-configuration-fields)
  1414. (unix-listener-configuration ,unix-listener-configuration-fields)
  1415. (fifo-listener-configuration ,fifo-listener-configuration-fields)
  1416. (inet-listener-configuration ,inet-listener-configuration-fields)
  1417. (namespace-configuration
  1418. ,namespace-configuration-fields
  1419. (mailboxes mailbox-configuration))
  1420. (mailbox-configuration ,mailbox-configuration-fields)
  1421. (service-configuration
  1422. ,service-configuration-fields
  1423. (listeners unix-listener-configuration fifo-listener-configuration
  1424. inet-listener-configuration))
  1425. (protocol-configuration ,protocol-configuration-fields))
  1426. 'dovecot-configuration))
  1427. ;;;
  1428. ;;; OpenSMTPD.
  1429. ;;;
  1430. (define-record-type* <opensmtpd-configuration>
  1431. opensmtpd-configuration make-opensmtpd-configuration
  1432. opensmtpd-configuration?
  1433. (package opensmtpd-configuration-package
  1434. (default opensmtpd))
  1435. (config-file opensmtpd-configuration-config-file
  1436. (default %default-opensmtpd-config-file)))
  1437. (define %default-opensmtpd-config-file
  1438. (plain-file "smtpd.conf" "
  1439. listen on lo
  1440. action inbound mbox
  1441. match for local action inbound
  1442. action outbound relay
  1443. match from local for any action outbound
  1444. "))
  1445. (define opensmtpd-shepherd-service
  1446. (match-lambda
  1447. (($ <opensmtpd-configuration> package config-file)
  1448. (list (shepherd-service
  1449. (provision '(smtpd))
  1450. (requirement '(loopback))
  1451. (documentation "Run the OpenSMTPD daemon.")
  1452. (start (let ((smtpd (file-append package "/sbin/smtpd")))
  1453. #~(make-forkexec-constructor
  1454. (list #$smtpd "-f" #$config-file)
  1455. #:pid-file "/var/run/smtpd.pid")))
  1456. (stop #~(make-kill-destructor)))))))
  1457. (define %opensmtpd-accounts
  1458. (list (user-group
  1459. (name "smtpq")
  1460. (system? #t))
  1461. (user-account
  1462. (name "smtpd")
  1463. (group "nogroup")
  1464. (system? #t)
  1465. (comment "SMTP Daemon")
  1466. (home-directory "/var/empty")
  1467. (shell (file-append shadow "/sbin/nologin")))
  1468. (user-account
  1469. (name "smtpq")
  1470. (group "smtpq")
  1471. (system? #t)
  1472. (comment "SMTPD Queue")
  1473. (home-directory "/var/empty")
  1474. (shell (file-append shadow "/sbin/nologin")))))
  1475. (define opensmtpd-activation
  1476. (match-lambda
  1477. (($ <opensmtpd-configuration> package config-file)
  1478. (let ((smtpd (file-append package "/sbin/smtpd")))
  1479. #~(begin
  1480. (use-modules (guix build utils))
  1481. ;; Create mbox and spool directories.
  1482. (mkdir-p "/var/mail")
  1483. (mkdir-p "/var/spool/smtpd")
  1484. (chmod "/var/spool/smtpd" #o711)
  1485. (mkdir-p "/var/spool/mail")
  1486. (chmod "/var/spool/mail" #o711))))))
  1487. (define %opensmtpd-pam-services
  1488. (list (unix-pam-service "smtpd")))
  1489. (define opensmtpd-service-type
  1490. (service-type
  1491. (name 'opensmtpd)
  1492. (extensions
  1493. (list (service-extension account-service-type
  1494. (const %opensmtpd-accounts))
  1495. (service-extension activation-service-type
  1496. opensmtpd-activation)
  1497. (service-extension pam-root-service-type
  1498. (const %opensmtpd-pam-services))
  1499. (service-extension profile-service-type
  1500. (compose list opensmtpd-configuration-package))
  1501. (service-extension shepherd-root-service-type
  1502. opensmtpd-shepherd-service)))))
  1503. ;;;
  1504. ;;; mail aliases.
  1505. ;;;
  1506. (define (mail-aliases-etc aliases)
  1507. `(("aliases" ,(plain-file "aliases"
  1508. ;; Ideally we'd use a format string like
  1509. ;; "~:{~a: ~{~a~^,~}\n~}", but it gives a
  1510. ;; warning that I can't figure out how to fix,
  1511. ;; so we'll just use string-join below instead.
  1512. (format #f "~:{~a: ~a\n~}"
  1513. (map (match-lambda
  1514. ((alias addresses ...)
  1515. (list alias (string-join addresses ","))))
  1516. aliases))))))
  1517. (define mail-aliases-service-type
  1518. (service-type
  1519. (name 'mail-aliases)
  1520. (extensions
  1521. (list (service-extension etc-service-type mail-aliases-etc)))
  1522. (compose concatenate)
  1523. (extend append)))
  1524. ;;;
  1525. ;;; Exim.
  1526. ;;;
  1527. (define-record-type* <exim-configuration> exim-configuration
  1528. make-exim-configuration
  1529. exim-configuration?
  1530. (package exim-configuration-package ;<package>
  1531. (default exim))
  1532. (config-file exim-configuration-config-file ;file-like
  1533. (default #f)))
  1534. (define %exim-accounts
  1535. (list (user-group
  1536. (name "exim")
  1537. (system? #t))
  1538. (user-account
  1539. (name "exim")
  1540. (group "exim")
  1541. (system? #t)
  1542. (comment "Exim Daemon")
  1543. (home-directory "/var/empty")
  1544. (shell (file-append shadow "/sbin/nologin")))))
  1545. (define (exim-computed-config-file package config-file)
  1546. (computed-file "exim.conf"
  1547. #~(call-with-output-file #$output
  1548. (lambda (port)
  1549. (format port "
  1550. exim_user = exim
  1551. exim_group = exim
  1552. .include ~a"
  1553. #$(or config-file
  1554. (file-append package "/etc/exim.conf")))))))
  1555. (define exim-shepherd-service
  1556. (match-lambda
  1557. (($ <exim-configuration> package config-file)
  1558. (list (shepherd-service
  1559. (provision '(exim mta))
  1560. (documentation "Run the exim daemon.")
  1561. (requirement '(networking))
  1562. (start #~(make-forkexec-constructor
  1563. '(#$(file-append package "/bin/exim")
  1564. "-bd" "-v" "-C"
  1565. #$(exim-computed-config-file package config-file))))
  1566. (stop #~(make-kill-destructor)))))))
  1567. (define exim-activation
  1568. (match-lambda
  1569. (($ <exim-configuration> package config-file)
  1570. (with-imported-modules '((guix build utils))
  1571. #~(begin
  1572. (use-modules (guix build utils))
  1573. (let ((uid (passwd:uid (getpw "exim")))
  1574. (gid (group:gid (getgr "exim"))))
  1575. (mkdir-p "/var/spool/exim")
  1576. (chown "/var/spool/exim" uid gid))
  1577. (zero? (system* #$(file-append package "/bin/exim")
  1578. "-bV" "-C" #$(exim-computed-config-file package config-file))))))))
  1579. (define exim-profile
  1580. (compose list exim-configuration-package))
  1581. (define exim-service-type
  1582. (service-type
  1583. (name 'exim)
  1584. (extensions
  1585. (list (service-extension shepherd-root-service-type exim-shepherd-service)
  1586. (service-extension account-service-type (const %exim-accounts))
  1587. (service-extension activation-service-type exim-activation)
  1588. (service-extension profile-service-type exim-profile)
  1589. (service-extension mail-aliases-service-type (const '()))))))
  1590. ;;;
  1591. ;;; GNU Mailutils IMAP4 Daemon.
  1592. ;;;
  1593. (define %default-imap4d-config-file
  1594. (plain-file "imap4d.conf" "server localhost {};\n"))
  1595. (define-record-type* <imap4d-configuration>
  1596. imap4d-configuration make-imap4d-configuration imap4d-configuration?
  1597. (package imap4d-configuration-package
  1598. (default mailutils))
  1599. (config-file imap4d-configuration-config-file
  1600. (default %default-imap4d-config-file)))
  1601. (define imap4d-shepherd-service
  1602. (match-lambda
  1603. (($ <imap4d-configuration> package config-file)
  1604. (list (shepherd-service
  1605. (provision '(imap4d))
  1606. (requirement '(networking syslogd))
  1607. (documentation "Run the imap4d daemon.")
  1608. (start (let ((imap4d (file-append package "/sbin/imap4d")))
  1609. #~(make-forkexec-constructor
  1610. (list #$imap4d "--daemon" "--foreground"
  1611. "--config-file" #$config-file))))
  1612. (stop #~(make-kill-destructor)))))))
  1613. (define imap4d-service-type
  1614. (service-type
  1615. (name 'imap4d)
  1616. (description
  1617. "Run the GNU @command{imap4d} to serve e-mail messages through IMAP.")
  1618. (extensions
  1619. (list (service-extension
  1620. shepherd-root-service-type imap4d-shepherd-service)))
  1621. (default-value (imap4d-configuration))))
  1622. ;;;
  1623. ;;; Radicale.
  1624. ;;;
  1625. (define-record-type* <radicale-configuration>
  1626. radicale-configuration make-radicale-configuration
  1627. radicale-configuration?
  1628. (package radicale-configuration-package
  1629. (default radicale))
  1630. (config-file radicale-configuration-config-file
  1631. (default %default-radicale-config-file)))
  1632. (define %default-radicale-config-file
  1633. (plain-file "radicale.conf" "
  1634. [auth]
  1635. type = htpasswd
  1636. htpasswd_filename = /var/lib/radicale/users
  1637. htpasswd_encryption = plain
  1638. [server]
  1639. hosts = localhost:5232"))
  1640. (define %radicale-accounts
  1641. (list (user-group
  1642. (name "radicale")
  1643. (system? #t))
  1644. (user-account
  1645. (name "radicale")
  1646. (group "radicale")
  1647. (system? #t)
  1648. (comment "Radicale Daemon")
  1649. (home-directory "/var/empty")
  1650. (shell (file-append shadow "/sbin/nologin")))))
  1651. (define radicale-shepherd-service
  1652. (match-lambda
  1653. (($ <radicale-configuration> package config-file)
  1654. (list (shepherd-service
  1655. (provision '(radicale))
  1656. (documentation "Run the radicale daemon.")
  1657. (requirement '(networking))
  1658. (start #~(make-forkexec-constructor
  1659. (list #$(file-append package "/bin/radicale")
  1660. "-C" #$config-file)
  1661. #:user "radicale"
  1662. #:group "radicale"))
  1663. (stop #~(make-kill-destructor)))))))
  1664. (define radicale-activation
  1665. (match-lambda
  1666. (($ <radicale-configuration> package config-file)
  1667. (with-imported-modules '((guix build utils))
  1668. #~(begin
  1669. (use-modules (guix build utils))
  1670. (let ((uid (passwd:uid (getpw "radicale")))
  1671. (gid (group:gid (getgr "radicale"))))
  1672. (mkdir-p "/var/lib/radicale/collections")
  1673. (chown "/var/lib/radicale" uid gid)
  1674. (chown "/var/lib/radicale/collections" uid gid)
  1675. (chmod "/var/lib/radicale" #o700)))))))
  1676. (define radicale-service-type
  1677. (service-type
  1678. (name 'radicale)
  1679. (description "Run radicale, a small CalDAV and CardDAV server.")
  1680. (extensions
  1681. (list (service-extension shepherd-root-service-type radicale-shepherd-service)
  1682. (service-extension account-service-type (const %radicale-accounts))
  1683. (service-extension activation-service-type radicale-activation)))
  1684. (default-value (radicale-configuration))))