guix.scm 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019 Christopher Baines <mail@cbaines.net>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify
  7. ;;; it under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation, either version 3 of the License, or
  9. ;;; (at your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful,
  12. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu services guix)
  19. #:use-module (srfi srfi-1)
  20. #:use-module (ice-9 match)
  21. #:use-module (guix gexp)
  22. #:use-module (guix records)
  23. #:use-module (guix packages)
  24. #:use-module ((gnu packages base)
  25. #:select (glibc-utf8-locales))
  26. #:use-module (gnu packages admin)
  27. #:use-module (gnu packages databases)
  28. #:use-module (gnu packages web)
  29. #:use-module (gnu packages guile)
  30. #:use-module (gnu packages guile-xyz)
  31. #:use-module (gnu packages package-management)
  32. #:use-module (gnu services)
  33. #:use-module (gnu services base)
  34. #:use-module (gnu services admin)
  35. #:use-module (gnu services shepherd)
  36. #:use-module (gnu services getmail)
  37. #:use-module (gnu system shadow)
  38. #:export (guix-build-coordinator-configuration
  39. guix-build-coordinator-configuration?
  40. guix-build-coordinator-configuration-package
  41. guix-build-coordinator-configuration-user
  42. guix-build-coordinator-configuration-group
  43. guix-build-coordinator-configuration-datastore-uri-string
  44. guix-build-coordinator-configuration-agent-communication-uri-string
  45. guix-build-coordinator-configuration-client-communication-uri-string
  46. guix-build-coordinator-configuration-allocation-strategy
  47. guix-build-coordinator-configuration-hooks
  48. guix-build-coordinator-configuration-guile
  49. guix-build-coordinator-service-type
  50. guix-build-coordinator-agent-configuration
  51. guix-build-coordinator-agent-configuration?
  52. guix-build-coordinator-agent-configuration-package
  53. guix-build-coordinator-agent-configuration-user
  54. guix-build-coordinator-agent-configuration-coordinator
  55. guix-build-coordinator-agent-configuration-uuid
  56. guix-build-coordinator-agent-configuration-password
  57. guix-build-coordinator-agent-configuration-password-file
  58. guix-build-coordinator-agent-configuration-systems
  59. guix-build-coordinator-agent-configuration-max-parallel-builds
  60. guix-build-coordinator-agent-configuration-derivation-substitute-urls
  61. guix-build-coordinator-agent-configuration-non-derivation-substitute-urls
  62. guix-build-coordinator-agent-service-type
  63. guix-build-coordinator-queue-builds-configuration
  64. guix-build-coordinator-queue-builds-configuration?
  65. guix-build-coordinator-queue-builds-configuration-package
  66. guix-build-coordinator-queue-builds-configuration-user
  67. guix-build-coordinator-queue-builds-coordinator
  68. guix-build-coordinator-queue-builds-configuration-systems
  69. guix-build-coordinator-queue-builds-configuration-system-and-targets
  70. guix-build-coordinator-queue-builds-configuration-guix-data-service
  71. guix-build-coordinator-queue-builds-configuration-processed-commits-file
  72. guix-build-coordinator-queue-builds-service-type
  73. <guix-data-service-configuration>
  74. guix-data-service-configuration
  75. guix-data-service-configuration?
  76. guix-data-service-package
  77. guix-data-service-user
  78. guix-data-service-group
  79. guix-data-service-port
  80. guix-data-service-host
  81. guix-data-service-getmail-idle-mailboxes
  82. guix-data-service-commits-getmail-retriever-configuration
  83. guix-data-service-type))
  84. ;;;; Commentary:
  85. ;;;
  86. ;;; Services specifically related to GNU Guix.
  87. ;;;
  88. ;;;; Code:
  89. (define-record-type* <guix-build-coordinator-configuration>
  90. guix-build-coordinator-configuration make-guix-build-coordinator-configuration
  91. guix-build-coordinator-configuration?
  92. (package guix-build-coordinator-configuration-package
  93. (default guix-build-coordinator))
  94. (user guix-build-coordinator-configuration-user
  95. (default "guix-build-coordinator"))
  96. (group guix-build-coordinator-configuration-group
  97. (default "guix-build-coordinator"))
  98. (database-uri-string
  99. guix-build-coordinator-configuration-datastore-uri-string
  100. (default "sqlite:///var/lib/guix-build-coordinator/guix_build_coordinator.db"))
  101. (agent-communication-uri-string
  102. guix-build-coordinator-configuration-agent-communication-uri-string
  103. (default "http://0.0.0.0:8745"))
  104. (client-communication-uri-string
  105. guix-build-coordinator-configuration-client-communication-uri-string
  106. (default "http://127.0.0.1:8746"))
  107. (allocation-strategy
  108. guix-build-coordinator-configuration-allocation-strategy
  109. (default #~basic-build-allocation-strategy))
  110. (hooks guix-build-coordinator-configuration-hooks
  111. (default '()))
  112. (guile guix-build-coordinator-configuration-guile
  113. (default guile-3.0-latest)))
  114. (define-record-type* <guix-build-coordinator-agent-configuration>
  115. guix-build-coordinator-agent-configuration
  116. make-guix-build-coordinator-agent-configuration
  117. guix-build-coordinator-agent-configuration?
  118. (package guix-build-coordinator-agent-configuration-package
  119. (default guix-build-coordinator))
  120. (user guix-build-coordinator-agent-configuration-user
  121. (default "guix-build-coordinator-agent"))
  122. (coordinator guix-build-coordinator-agent-configuration-coordinator
  123. (default "http://localhost:8745"))
  124. (uuid guix-build-coordinator-agent-configuration-uuid)
  125. (password guix-build-coordinator-agent-configuration-password
  126. (default #f))
  127. (password-file guix-build-coordinator-agent-configuration-password-file
  128. (default #f))
  129. (systems guix-build-coordinator-agent-configuration-systems
  130. (default #f))
  131. (max-parallel-builds
  132. guix-build-coordinator-agent-configuration-max-parallel-builds
  133. (default 1))
  134. (derivation-substitute-urls
  135. guix-build-coordinator-agent-configuration-derivation-substitute-urls
  136. (default #f))
  137. (non-derivation-substitute-urls
  138. guix-build-coordinator-agent-configuration-non-derivation-substitute-urls
  139. (default #f)))
  140. (define-record-type* <guix-build-coordinator-queue-builds-configuration>
  141. guix-build-coordinator-queue-builds-configuration
  142. make-guix-build-coordinator-queue-builds-configuration
  143. guix-build-coordinator-queue-builds-configuration?
  144. (package guix-build-coordinator-queue-builds-configuration-package
  145. (default guix-build-coordinator))
  146. (user guix-build-coordinator-queue-builds-configuration-user
  147. (default "guix-build-coordinator-queue-builds"))
  148. (coordinator guix-build-coordinator-queue-builds-coordinator
  149. (default "http://localhost:8745"))
  150. (systems guix-build-coordinator-queue-builds-configuration-systems
  151. (default #f))
  152. (systems-and-targets
  153. guix-build-coordinator-queue-builds-configuration-system-and-targets
  154. (default #f))
  155. (guix-data-service
  156. guix-build-coordinator-queue-builds-configuration-guix-data-service
  157. (default "https://data.guix.gnu.org"))
  158. (processed-commits-file
  159. guix-build-coordinator-queue-builds-configuration-processed-commits-file
  160. (default "/var/cache/guix-build-coordinator-queue-builds/processed-commits")))
  161. (define* (make-guix-build-coordinator-start-script database-uri-string
  162. allocation-strategy
  163. pid-file
  164. guix-build-coordinator-package
  165. #:key
  166. agent-communication-uri-string
  167. client-communication-uri-string
  168. (hooks '())
  169. (guile guile-3.0))
  170. (program-file
  171. "start-guix-build-coordinator"
  172. (with-extensions (cons guix-build-coordinator-package
  173. ;; This is a poorly constructed Guile load path,
  174. ;; since it contains things that aren't Guile
  175. ;; libraries, but it means that the Guile libraries
  176. ;; needed for the Guix Build Coordinator don't need
  177. ;; to be individually specified here.
  178. (map second (package-inputs
  179. guix-build-coordinator-package)))
  180. #~(begin
  181. (use-modules (srfi srfi-1)
  182. (ice-9 match)
  183. (web uri)
  184. (prometheus)
  185. (guix-build-coordinator hooks)
  186. (guix-build-coordinator datastore)
  187. (guix-build-coordinator build-allocator)
  188. (guix-build-coordinator coordinator))
  189. (let* ((metrics-registry (make-metrics-registry
  190. #:namespace
  191. "guixbuildcoordinator_"))
  192. (datastore (database-uri->datastore
  193. #$database-uri-string
  194. #:metrics-registry metrics-registry))
  195. (hooks
  196. (list #$@(map (match-lambda
  197. ((name . hook-gexp)
  198. #~(cons name #$hook-gexp)))
  199. hooks)))
  200. (hooks-with-defaults
  201. `(,@hooks
  202. ,@(remove (match-lambda
  203. ((name . _) (assq-ref hooks name)))
  204. %default-hooks)))
  205. (build-coordinator (make-build-coordinator
  206. #:datastore datastore
  207. #:hooks hooks-with-defaults
  208. #:metrics-registry metrics-registry
  209. #:allocation-strategy #$allocation-strategy)))
  210. (run-coordinator-service
  211. build-coordinator
  212. #:update-datastore? #t
  213. #:pid-file #$pid-file
  214. #:agent-communication-uri (string->uri
  215. #$agent-communication-uri-string)
  216. #:client-communication-uri (string->uri
  217. #$client-communication-uri-string)))))
  218. #:guile guile))
  219. (define (guix-build-coordinator-shepherd-services config)
  220. (match-record config <guix-build-coordinator-configuration>
  221. (package user group database-uri-string
  222. agent-communication-uri-string
  223. client-communication-uri-string
  224. allocation-strategy
  225. hooks
  226. guile)
  227. (list
  228. (shepherd-service
  229. (documentation "Guix Build Coordinator")
  230. (provision '(guix-build-coordinator))
  231. (requirement '(networking))
  232. (start #~(make-forkexec-constructor
  233. (list #$(make-guix-build-coordinator-start-script
  234. database-uri-string
  235. allocation-strategy
  236. "/var/run/guix-build-coordinator/pid"
  237. package
  238. #:agent-communication-uri-string
  239. agent-communication-uri-string
  240. #:client-communication-uri-string
  241. client-communication-uri-string
  242. #:hooks hooks
  243. #:guile guile))
  244. #:user #$user
  245. #:group #$group
  246. #:pid-file "/var/run/guix-build-coordinator/pid"
  247. ;; Allow time for migrations to run
  248. #:pid-file-timeout 60
  249. #:environment-variables
  250. `(,(string-append
  251. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  252. "LC_ALL=en_US.utf8")
  253. #:log-file "/var/log/guix-build-coordinator/coordinator.log"))
  254. (stop #~(make-kill-destructor))))))
  255. (define (guix-build-coordinator-activation config)
  256. #~(begin
  257. (use-modules (guix build utils))
  258. (define %user (getpw "guix-build-coordinator"))
  259. (chmod "/var/lib/guix-build-coordinator" #o755)
  260. (mkdir-p "/var/log/guix-build-coordinator")
  261. ;; Allow writing the PID file
  262. (mkdir-p "/var/run/guix-build-coordinator")
  263. (chown "/var/run/guix-build-coordinator"
  264. (passwd:uid %user)
  265. (passwd:gid %user))))
  266. (define (guix-build-coordinator-account config)
  267. (match-record config <guix-build-coordinator-configuration>
  268. (user group)
  269. (list (user-group
  270. (name group)
  271. (system? #t))
  272. (user-account
  273. (name user)
  274. (group group)
  275. (system? #t)
  276. (comment "Guix Build Coordinator user")
  277. (home-directory "/var/lib/guix-build-coordinator")
  278. (shell (file-append shadow "/sbin/nologin"))))))
  279. (define guix-build-coordinator-service-type
  280. (service-type
  281. (name 'guix-build-coordinator)
  282. (extensions
  283. (list
  284. (service-extension shepherd-root-service-type
  285. guix-build-coordinator-shepherd-services)
  286. (service-extension activation-service-type
  287. guix-build-coordinator-activation)
  288. (service-extension account-service-type
  289. guix-build-coordinator-account)))
  290. (default-value
  291. (guix-build-coordinator-configuration))
  292. (description
  293. "Run an instance of the Guix Build Coordinator.")))
  294. (define (guix-build-coordinator-agent-shepherd-services config)
  295. (match-record config <guix-build-coordinator-agent-configuration>
  296. (package user coordinator uuid password password-file max-parallel-builds
  297. derivation-substitute-urls non-derivation-substitute-urls
  298. systems)
  299. (list
  300. (shepherd-service
  301. (documentation "Guix Build Coordinator Agent")
  302. (provision '(guix-build-coordinator-agent))
  303. (requirement '(networking))
  304. (start #~(make-forkexec-constructor
  305. (list #$(file-append package "/bin/guix-build-coordinator-agent")
  306. #$(string-append "--coordinator=" coordinator)
  307. #$(string-append "--uuid=" uuid)
  308. #$@(if password
  309. #~(#$(string-append "--password=" password))
  310. #~())
  311. #$@(if password-file
  312. #~(#$(string-append "--password-file=" password-file))
  313. #~())
  314. #$(simple-format #f "--max-parallel-builds=~A"
  315. max-parallel-builds)
  316. #$@(if derivation-substitute-urls
  317. #~(#$(string-append
  318. "--derivation-substitute-urls="
  319. (string-join derivation-substitute-urls " ")))
  320. #~())
  321. #$@(if non-derivation-substitute-urls
  322. #~(#$(string-append
  323. "--non-derivation-substitute-urls="
  324. (string-join derivation-substitute-urls " ")))
  325. #~())
  326. #$@(map (lambda (system)
  327. (string-append "--system=" system))
  328. (or systems '())))
  329. #:user #$user
  330. #:pid-file "/var/run/guix-build-coordinator-agent/pid"
  331. #:environment-variables
  332. `(,(string-append
  333. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  334. "LC_ALL=en_US.utf8")
  335. #:log-file "/var/log/guix-build-coordinator/agent.log"))
  336. (stop #~(make-kill-destructor))))))
  337. (define (guix-build-coordinator-agent-activation config)
  338. #~(begin
  339. (use-modules (guix build utils))
  340. (mkdir-p "/var/log/guix-build-coordinator")
  341. ;; Allow writing the PID file
  342. (mkdir-p "/var/run/guix-build-coordinator-agent")
  343. (chown "/var/run/guix-build-coordinator-agent"
  344. (passwd:uid %user)
  345. (passwd:gid %user))))
  346. (define (guix-build-coordinator-agent-account config)
  347. (list (user-account
  348. (name (guix-build-coordinator-agent-configuration-user config))
  349. (group "nogroup")
  350. (system? #t)
  351. (comment "Guix Build Coordinator agent user")
  352. (home-directory "/var/empty")
  353. (shell (file-append shadow "/sbin/nologin")))))
  354. (define guix-build-coordinator-agent-service-type
  355. (service-type
  356. (name 'guix-build-coordinator-agent)
  357. (extensions
  358. (list
  359. (service-extension shepherd-root-service-type
  360. guix-build-coordinator-agent-shepherd-services)
  361. (service-extension activation-service-type
  362. guix-build-coordinator-agent-activation)
  363. (service-extension account-service-type
  364. guix-build-coordinator-agent-account)))
  365. (description
  366. "Run a Guix Build Coordinator agent.")))
  367. (define (guix-build-coordinator-queue-builds-shepherd-services config)
  368. (match-record config <guix-build-coordinator-queue-builds-configuration>
  369. (package user coordinator systems systems-and-targets
  370. guix-data-service processed-commits-file)
  371. (list
  372. (shepherd-service
  373. (documentation "Guix Build Coordinator queue builds from Guix Data Service")
  374. (provision '(guix-build-coordinator-queue-builds))
  375. (requirement '(networking))
  376. (start
  377. #~(make-forkexec-constructor
  378. (list
  379. #$(file-append
  380. package
  381. "/bin/guix-build-coordinator-queue-builds-from-guix-data-service")
  382. #$(string-append "--coordinator=" coordinator)
  383. #$@(map (lambda (system)
  384. (string-append "--system=" system))
  385. (or systems '()))
  386. #$@(map (match-lambda
  387. ((system . target)
  388. (string-append "--system-and-target=" system "=" target)))
  389. (or systems-and-targets '()))
  390. #$@(if guix-data-service
  391. #~(#$(string-append "--guix-data-service=" guix-data-service))
  392. #~())
  393. #$@(if processed-commits-file
  394. #~(#$(string-append "--processed-commits-file="
  395. processed-commits-file))
  396. #~()))
  397. #:user #$user
  398. #:pid-file "/var/run/guix-build-coordinator-queue-builds/pid"
  399. #:environment-variables
  400. `(,(string-append
  401. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  402. "LC_ALL=en_US.utf8")
  403. #:log-file "/var/log/guix-build-coordinator/queue-builds.log"))
  404. (stop #~(make-kill-destructor))))))
  405. (define (guix-build-coordinator-queue-builds-activation config)
  406. #~(begin
  407. (use-modules (guix build utils))
  408. (mkdir-p "/var/log/guix-build-coordinator")
  409. ;; Allow writing the PID file
  410. (mkdir-p "/var/run/guix-build-coordinator-queue-builds")
  411. (chown "/var/run/guix-build-coordinator-queue-builds"
  412. (passwd:uid %user)
  413. (passwd:gid %user))))
  414. (define (guix-build-coordinator-queue-builds-account config)
  415. (list (user-account
  416. (name (guix-build-coordinator-queue-builds-configuration-user config))
  417. (group "nogroup")
  418. (system? #t)
  419. (comment "Guix Build Coordinator queue-builds user")
  420. (home-directory "/var/empty")
  421. (shell (file-append shadow "/sbin/nologin")))))
  422. (define guix-build-coordinator-queue-builds-service-type
  423. (service-type
  424. (name 'guix-build-coordinator-queue-builds)
  425. (extensions
  426. (list
  427. (service-extension shepherd-root-service-type
  428. guix-build-coordinator-queue-builds-shepherd-services)
  429. (service-extension activation-service-type
  430. guix-build-coordinator-queue-builds-activation)
  431. (service-extension account-service-type
  432. guix-build-coordinator-queue-builds-account)))
  433. (description
  434. "Run the guix-build-coordinator-queue-builds-from-guix-data-service
  435. script.
  436. This is a script to assist in having the Guix Build Coordinator build
  437. derivations stored in an instance of the Guix Data Service.")))
  438. ;;;
  439. ;;; Guix Data Service
  440. ;;;
  441. (define-record-type* <guix-data-service-configuration>
  442. guix-data-service-configuration make-guix-data-service-configuration
  443. guix-data-service-configuration?
  444. (package guix-data-service-package
  445. (default guix-data-service))
  446. (user guix-data-service-configuration-user
  447. (default "guix-data-service"))
  448. (group guix-data-service-configuration-group
  449. (default "guix-data-service"))
  450. (port guix-data-service-port
  451. (default 8765))
  452. (host guix-data-service-host
  453. (default "127.0.0.1"))
  454. (getmail-idle-mailboxes
  455. guix-data-service-getmail-idle-mailboxes
  456. (default #f))
  457. (commits-getmail-retriever-configuration
  458. guix-data-service-commits-getmail-retriever-configuration
  459. (default #f))
  460. (extra-options guix-data-service-extra-options
  461. (default '()))
  462. (extra-process-jobs-options
  463. guix-data-service-extra-process-jobs-options
  464. (default '())))
  465. (define (guix-data-service-profile-packages config)
  466. "Return the guix-data-service package, this will populate the
  467. ca-certificates.crt file in the system profile."
  468. (list
  469. (guix-data-service-package config)))
  470. (define (guix-data-service-shepherd-services config)
  471. (match-record config <guix-data-service-configuration>
  472. (package user group port host extra-options extra-process-jobs-options)
  473. (list
  474. (shepherd-service
  475. (documentation "Guix Data Service web server")
  476. (provision '(guix-data-service))
  477. (requirement '(postgres networking))
  478. (start #~(make-forkexec-constructor
  479. (list #$(file-append package
  480. "/bin/guix-data-service")
  481. "--pid-file=/var/run/guix-data-service/pid"
  482. #$(string-append "--port=" (number->string port))
  483. #$(string-append "--host=" host)
  484. ;; Perform any database migrations when the
  485. ;; service is started
  486. "--update-database"
  487. #$@extra-options)
  488. #:user #$user
  489. #:group #$group
  490. #:pid-file "/var/run/guix-data-service/pid"
  491. ;; Allow time for migrations to run
  492. #:pid-file-timeout 60
  493. #:environment-variables
  494. `(,(string-append
  495. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  496. "LC_ALL=en_US.UTF-8")
  497. #:log-file "/var/log/guix-data-service/web.log"))
  498. (stop #~(make-kill-destructor)))
  499. (shepherd-service
  500. (documentation "Guix Data Service process jobs")
  501. (provision '(guix-data-service-process-jobs))
  502. (requirement '(postgres
  503. networking
  504. ;; Require guix-data-service, as that the database
  505. ;; migrations are handled through this service
  506. guix-data-service))
  507. (start #~(make-forkexec-constructor
  508. (list
  509. #$(file-append package
  510. "/bin/guix-data-service-process-jobs")
  511. #$@extra-process-jobs-options)
  512. #:user #$user
  513. #:group #$group
  514. #:environment-variables
  515. `("HOME=/var/lib/guix-data-service"
  516. "GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt"
  517. ,(string-append
  518. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  519. "LC_ALL=en_US.UTF-8")
  520. #:log-file "/var/log/guix-data-service/process-jobs.log"))
  521. (stop #~(make-kill-destructor))))))
  522. (define (guix-data-service-activation config)
  523. #~(begin
  524. (use-modules (guix build utils))
  525. (define %user (getpw "guix-data-service"))
  526. (chmod "/var/lib/guix-data-service" #o755)
  527. (mkdir-p "/var/log/guix-data-service")
  528. ;; Allow writing the PID file
  529. (mkdir-p "/var/run/guix-data-service")
  530. (chown "/var/run/guix-data-service"
  531. (passwd:uid %user)
  532. (passwd:gid %user))))
  533. (define (guix-data-service-account config)
  534. (match-record config <guix-data-service-configuration>
  535. (user group)
  536. (list (user-group
  537. (name group)
  538. (system? #t))
  539. (user-account
  540. (name user)
  541. (group group)
  542. (system? #t)
  543. (comment "Guix Data Service user")
  544. (home-directory "/var/lib/guix-data-service")
  545. (shell (file-append shadow "/sbin/nologin"))))))
  546. (define (guix-data-service-getmail-configuration config)
  547. (match config
  548. (($ <guix-data-service-configuration> package user group
  549. port host
  550. #f #f)
  551. '())
  552. (($ <guix-data-service-configuration> package user group
  553. port host
  554. getmail-idle-mailboxes
  555. commits-getmail-retriever-configuration)
  556. (list
  557. (getmail-configuration
  558. (name 'guix-data-service)
  559. (user user)
  560. (group group)
  561. (directory "/var/lib/getmail/guix-data-service")
  562. (rcfile
  563. (getmail-configuration-file
  564. (retriever commits-getmail-retriever-configuration)
  565. (destination
  566. (getmail-destination-configuration
  567. (type "MDA_external")
  568. (path (file-append
  569. package
  570. "/bin/guix-data-service-process-branch-updated-email"))))
  571. (options
  572. (getmail-options-configuration
  573. (read-all #f)
  574. (delivered-to #f)
  575. (received #f)))))
  576. (idle getmail-idle-mailboxes))))))
  577. (define guix-data-service-type
  578. (service-type
  579. (name 'guix-data-service)
  580. (extensions
  581. (list
  582. (service-extension profile-service-type
  583. guix-data-service-profile-packages)
  584. (service-extension shepherd-root-service-type
  585. guix-data-service-shepherd-services)
  586. (service-extension activation-service-type
  587. guix-data-service-activation)
  588. (service-extension account-service-type
  589. guix-data-service-account)
  590. (service-extension getmail-service-type
  591. guix-data-service-getmail-configuration)))
  592. (default-value
  593. (guix-data-service-configuration))
  594. (description
  595. "Run an instance of the Guix Data Service.")))