guix.scm 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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. (append
  179. (map second (package-inputs
  180. guix-build-coordinator-package))
  181. (map second (package-propagated-inputs
  182. guix-build-coordinator-package))))
  183. #~(begin
  184. (use-modules (srfi srfi-1)
  185. (ice-9 match)
  186. (web uri)
  187. (prometheus)
  188. (guix-build-coordinator hooks)
  189. (guix-build-coordinator datastore)
  190. (guix-build-coordinator build-allocator)
  191. (guix-build-coordinator coordinator))
  192. (setvbuf (current-output-port) 'line)
  193. (setvbuf (current-error-port) 'line)
  194. (simple-format #t "starting the guix-build-coordinator:\n ~A\n"
  195. (current-filename))
  196. (let* ((metrics-registry (make-metrics-registry
  197. #:namespace
  198. "guixbuildcoordinator"))
  199. (datastore (database-uri->datastore
  200. #$database-uri-string
  201. #:metrics-registry metrics-registry))
  202. (hooks
  203. (list #$@(map (match-lambda
  204. ((name . hook-gexp)
  205. #~(cons '#$name #$hook-gexp)))
  206. hooks)))
  207. (hooks-with-defaults
  208. `(,@hooks
  209. ,@(remove (match-lambda
  210. ((name . _) (assq-ref hooks name)))
  211. %default-hooks)))
  212. (build-coordinator (make-build-coordinator
  213. #:datastore datastore
  214. #:hooks hooks-with-defaults
  215. #:metrics-registry metrics-registry
  216. #:allocation-strategy #$allocation-strategy)))
  217. (run-coordinator-service
  218. build-coordinator
  219. #:update-datastore? #t
  220. #:pid-file #$pid-file
  221. #:agent-communication-uri (string->uri
  222. #$agent-communication-uri-string)
  223. #:client-communication-uri (string->uri
  224. #$client-communication-uri-string)))))
  225. #:guile guile))
  226. (define (guix-build-coordinator-shepherd-services config)
  227. (match-record config <guix-build-coordinator-configuration>
  228. (package user group database-uri-string
  229. agent-communication-uri-string
  230. client-communication-uri-string
  231. allocation-strategy
  232. hooks
  233. guile)
  234. (list
  235. (shepherd-service
  236. (documentation "Guix Build Coordinator")
  237. (provision '(guix-build-coordinator))
  238. (requirement '(networking))
  239. (start #~(make-forkexec-constructor
  240. (list #$(make-guix-build-coordinator-start-script
  241. database-uri-string
  242. allocation-strategy
  243. "/var/run/guix-build-coordinator/pid"
  244. package
  245. #:agent-communication-uri-string
  246. agent-communication-uri-string
  247. #:client-communication-uri-string
  248. client-communication-uri-string
  249. #:hooks hooks
  250. #:guile guile))
  251. #:user #$user
  252. #:group #$group
  253. #:pid-file "/var/run/guix-build-coordinator/pid"
  254. ;; Allow time for migrations to run
  255. #:pid-file-timeout 60
  256. #:environment-variables
  257. `(,(string-append
  258. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  259. "LC_ALL=en_US.utf8"
  260. "PATH=/run/current-system/profile/bin") ; for hooks
  261. #:log-file "/var/log/guix-build-coordinator/coordinator.log"))
  262. (stop #~(make-kill-destructor))))))
  263. (define (guix-build-coordinator-activation config)
  264. #~(begin
  265. (use-modules (guix build utils))
  266. (define %user (getpw "guix-build-coordinator"))
  267. (chmod "/var/lib/guix-build-coordinator" #o755)
  268. (mkdir-p "/var/log/guix-build-coordinator")
  269. ;; Allow writing the PID file
  270. (mkdir-p "/var/run/guix-build-coordinator")
  271. (chown "/var/run/guix-build-coordinator"
  272. (passwd:uid %user)
  273. (passwd:gid %user))))
  274. (define (guix-build-coordinator-account config)
  275. (match-record config <guix-build-coordinator-configuration>
  276. (user group)
  277. (list (user-group
  278. (name group)
  279. (system? #t))
  280. (user-account
  281. (name user)
  282. (group group)
  283. (system? #t)
  284. (comment "Guix Build Coordinator user")
  285. (home-directory "/var/lib/guix-build-coordinator")
  286. (shell (file-append shadow "/sbin/nologin"))))))
  287. (define guix-build-coordinator-service-type
  288. (service-type
  289. (name 'guix-build-coordinator)
  290. (extensions
  291. (list
  292. (service-extension shepherd-root-service-type
  293. guix-build-coordinator-shepherd-services)
  294. (service-extension activation-service-type
  295. guix-build-coordinator-activation)
  296. (service-extension account-service-type
  297. guix-build-coordinator-account)))
  298. (default-value
  299. (guix-build-coordinator-configuration))
  300. (description
  301. "Run an instance of the Guix Build Coordinator.")))
  302. (define (guix-build-coordinator-agent-shepherd-services config)
  303. (match-record config <guix-build-coordinator-agent-configuration>
  304. (package user coordinator uuid password password-file max-parallel-builds
  305. derivation-substitute-urls non-derivation-substitute-urls
  306. systems)
  307. (list
  308. (shepherd-service
  309. (documentation "Guix Build Coordinator Agent")
  310. (provision '(guix-build-coordinator-agent))
  311. (requirement '(networking))
  312. (start #~(make-forkexec-constructor
  313. (list #$(file-append package "/bin/guix-build-coordinator-agent")
  314. #$(string-append "--coordinator=" coordinator)
  315. #$(string-append "--uuid=" uuid)
  316. #$@(if password
  317. #~(#$(string-append "--password=" password))
  318. #~())
  319. #$@(if password-file
  320. #~(#$(string-append "--password-file=" password-file))
  321. #~())
  322. #$(simple-format #f "--max-parallel-builds=~A"
  323. max-parallel-builds)
  324. #$@(if derivation-substitute-urls
  325. #~(#$(string-append
  326. "--derivation-substitute-urls="
  327. (string-join derivation-substitute-urls " ")))
  328. #~())
  329. #$@(if non-derivation-substitute-urls
  330. #~(#$(string-append
  331. "--non-derivation-substitute-urls="
  332. (string-join non-derivation-substitute-urls " ")))
  333. #~())
  334. #$@(map (lambda (system)
  335. (string-append "--system=" system))
  336. (or systems '())))
  337. #:user #$user
  338. #:environment-variables
  339. `(,(string-append
  340. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  341. ;; XDG_CACHE_HOME is used by Guix when caching narinfo files
  342. "XDG_CACHE_HOME=/var/cache/guix-build-coordinator-agent"
  343. "LC_ALL=en_US.utf8")
  344. #:log-file "/var/log/guix-build-coordinator/agent.log"))
  345. (stop #~(make-kill-destructor))))))
  346. (define (guix-build-coordinator-agent-activation config)
  347. #~(begin
  348. (use-modules (guix build utils))
  349. (define %user (getpw "guix-build-coordinator-agent"))
  350. (mkdir-p "/var/log/guix-build-coordinator")
  351. ;; Create a cache directory for storing narinfo files if downloaded
  352. (mkdir-p "/var/cache/guix-build-coordinator-agent")
  353. (chown "/var/cache/guix-build-coordinator-agent"
  354. (passwd:uid %user)
  355. (passwd:gid %user))))
  356. (define (guix-build-coordinator-agent-account config)
  357. (list (user-account
  358. (name (guix-build-coordinator-agent-configuration-user config))
  359. (group "nogroup")
  360. (system? #t)
  361. (comment "Guix Build Coordinator agent user")
  362. (home-directory "/var/empty")
  363. (shell (file-append shadow "/sbin/nologin")))))
  364. (define guix-build-coordinator-agent-service-type
  365. (service-type
  366. (name 'guix-build-coordinator-agent)
  367. (extensions
  368. (list
  369. (service-extension shepherd-root-service-type
  370. guix-build-coordinator-agent-shepherd-services)
  371. (service-extension activation-service-type
  372. guix-build-coordinator-agent-activation)
  373. (service-extension account-service-type
  374. guix-build-coordinator-agent-account)))
  375. (description
  376. "Run a Guix Build Coordinator agent.")))
  377. (define (guix-build-coordinator-queue-builds-shepherd-services config)
  378. (match-record config <guix-build-coordinator-queue-builds-configuration>
  379. (package user coordinator systems systems-and-targets
  380. guix-data-service processed-commits-file)
  381. (list
  382. (shepherd-service
  383. (documentation "Guix Build Coordinator queue builds from Guix Data Service")
  384. (provision '(guix-build-coordinator-queue-builds))
  385. (requirement '(networking))
  386. (start
  387. #~(make-forkexec-constructor
  388. (list
  389. #$(file-append
  390. package
  391. "/bin/guix-build-coordinator-queue-builds-from-guix-data-service")
  392. #$(string-append "--coordinator=" coordinator)
  393. #$@(map (lambda (system)
  394. (string-append "--system=" system))
  395. (or systems '()))
  396. #$@(map (match-lambda
  397. ((system . target)
  398. (string-append "--system-and-target=" system "=" target)))
  399. (or systems-and-targets '()))
  400. #$@(if guix-data-service
  401. #~(#$(string-append "--guix-data-service=" guix-data-service))
  402. #~())
  403. #$@(if processed-commits-file
  404. #~(#$(string-append "--processed-commits-file="
  405. processed-commits-file))
  406. #~()))
  407. #:user #$user
  408. #:pid-file "/var/run/guix-build-coordinator-queue-builds/pid"
  409. #:environment-variables
  410. `(,(string-append
  411. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  412. "LC_ALL=en_US.utf8")
  413. #:log-file "/var/log/guix-build-coordinator/queue-builds.log"))
  414. (stop #~(make-kill-destructor))))))
  415. (define (guix-build-coordinator-queue-builds-activation config)
  416. #~(begin
  417. (use-modules (guix build utils))
  418. (mkdir-p "/var/log/guix-build-coordinator")
  419. ;; Allow writing the PID file
  420. (mkdir-p "/var/run/guix-build-coordinator-queue-builds")
  421. (chown "/var/run/guix-build-coordinator-queue-builds"
  422. (passwd:uid %user)
  423. (passwd:gid %user))))
  424. (define (guix-build-coordinator-queue-builds-account config)
  425. (list (user-account
  426. (name (guix-build-coordinator-queue-builds-configuration-user config))
  427. (group "nogroup")
  428. (system? #t)
  429. (comment "Guix Build Coordinator queue-builds user")
  430. (home-directory "/var/empty")
  431. (shell (file-append shadow "/sbin/nologin")))))
  432. (define guix-build-coordinator-queue-builds-service-type
  433. (service-type
  434. (name 'guix-build-coordinator-queue-builds)
  435. (extensions
  436. (list
  437. (service-extension shepherd-root-service-type
  438. guix-build-coordinator-queue-builds-shepherd-services)
  439. (service-extension activation-service-type
  440. guix-build-coordinator-queue-builds-activation)
  441. (service-extension account-service-type
  442. guix-build-coordinator-queue-builds-account)))
  443. (description
  444. "Run the guix-build-coordinator-queue-builds-from-guix-data-service
  445. script.
  446. This is a script to assist in having the Guix Build Coordinator build
  447. derivations stored in an instance of the Guix Data Service.")))
  448. ;;;
  449. ;;; Guix Data Service
  450. ;;;
  451. (define-record-type* <guix-data-service-configuration>
  452. guix-data-service-configuration make-guix-data-service-configuration
  453. guix-data-service-configuration?
  454. (package guix-data-service-package
  455. (default guix-data-service))
  456. (user guix-data-service-configuration-user
  457. (default "guix-data-service"))
  458. (group guix-data-service-configuration-group
  459. (default "guix-data-service"))
  460. (port guix-data-service-port
  461. (default 8765))
  462. (host guix-data-service-host
  463. (default "127.0.0.1"))
  464. (getmail-idle-mailboxes
  465. guix-data-service-getmail-idle-mailboxes
  466. (default #f))
  467. (commits-getmail-retriever-configuration
  468. guix-data-service-commits-getmail-retriever-configuration
  469. (default #f))
  470. (extra-options guix-data-service-extra-options
  471. (default '()))
  472. (extra-process-jobs-options
  473. guix-data-service-extra-process-jobs-options
  474. (default '())))
  475. (define (guix-data-service-profile-packages config)
  476. "Return the guix-data-service package, this will populate the
  477. ca-certificates.crt file in the system profile."
  478. (list
  479. (guix-data-service-package config)))
  480. (define (guix-data-service-shepherd-services config)
  481. (match-record config <guix-data-service-configuration>
  482. (package user group port host extra-options extra-process-jobs-options)
  483. (list
  484. (shepherd-service
  485. (documentation "Guix Data Service web server")
  486. (provision '(guix-data-service))
  487. (requirement '(postgres networking))
  488. (start #~(make-forkexec-constructor
  489. (list #$(file-append package
  490. "/bin/guix-data-service")
  491. "--pid-file=/var/run/guix-data-service/pid"
  492. #$(string-append "--port=" (number->string port))
  493. #$(string-append "--host=" host)
  494. ;; Perform any database migrations when the
  495. ;; service is started
  496. "--update-database"
  497. #$@extra-options)
  498. #:user #$user
  499. #:group #$group
  500. #:pid-file "/var/run/guix-data-service/pid"
  501. ;; Allow time for migrations to run
  502. #:pid-file-timeout 60
  503. #:environment-variables
  504. `(,(string-append
  505. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  506. "LC_ALL=en_US.UTF-8")
  507. #:log-file "/var/log/guix-data-service/web.log"))
  508. (stop #~(make-kill-destructor)))
  509. (shepherd-service
  510. (documentation "Guix Data Service process jobs")
  511. (provision '(guix-data-service-process-jobs))
  512. (requirement '(postgres
  513. networking
  514. ;; Require guix-data-service, as that the database
  515. ;; migrations are handled through this service
  516. guix-data-service))
  517. (start #~(make-forkexec-constructor
  518. (list
  519. #$(file-append package
  520. "/bin/guix-data-service-process-jobs")
  521. #$@extra-process-jobs-options)
  522. #:user #$user
  523. #:group #$group
  524. #:environment-variables
  525. `("HOME=/var/lib/guix-data-service"
  526. "GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt"
  527. ,(string-append
  528. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  529. "LC_ALL=en_US.UTF-8")
  530. #:log-file "/var/log/guix-data-service/process-jobs.log"))
  531. (stop #~(make-kill-destructor))))))
  532. (define (guix-data-service-activation config)
  533. #~(begin
  534. (use-modules (guix build utils))
  535. (define %user (getpw "guix-data-service"))
  536. (chmod "/var/lib/guix-data-service" #o755)
  537. (mkdir-p "/var/log/guix-data-service")
  538. ;; Allow writing the PID file
  539. (mkdir-p "/var/run/guix-data-service")
  540. (chown "/var/run/guix-data-service"
  541. (passwd:uid %user)
  542. (passwd:gid %user))))
  543. (define (guix-data-service-account config)
  544. (match-record config <guix-data-service-configuration>
  545. (user group)
  546. (list (user-group
  547. (name group)
  548. (system? #t))
  549. (user-account
  550. (name user)
  551. (group group)
  552. (system? #t)
  553. (comment "Guix Data Service user")
  554. (home-directory "/var/lib/guix-data-service")
  555. (shell (file-append shadow "/sbin/nologin"))))))
  556. (define (guix-data-service-getmail-configuration config)
  557. (match config
  558. (($ <guix-data-service-configuration> package user group
  559. port host
  560. #f #f)
  561. '())
  562. (($ <guix-data-service-configuration> package user group
  563. port host
  564. getmail-idle-mailboxes
  565. commits-getmail-retriever-configuration)
  566. (list
  567. (getmail-configuration
  568. (name 'guix-data-service)
  569. (user user)
  570. (group group)
  571. (directory "/var/lib/getmail/guix-data-service")
  572. (rcfile
  573. (getmail-configuration-file
  574. (retriever commits-getmail-retriever-configuration)
  575. (destination
  576. (getmail-destination-configuration
  577. (type "MDA_external")
  578. (path (file-append
  579. package
  580. "/bin/guix-data-service-process-branch-updated-email"))))
  581. (options
  582. (getmail-options-configuration
  583. (read-all #f)
  584. (delivered-to #f)
  585. (received #f)))))
  586. (idle getmail-idle-mailboxes))))))
  587. (define guix-data-service-type
  588. (service-type
  589. (name 'guix-data-service)
  590. (extensions
  591. (list
  592. (service-extension profile-service-type
  593. guix-data-service-profile-packages)
  594. (service-extension shepherd-root-service-type
  595. guix-data-service-shepherd-services)
  596. (service-extension activation-service-type
  597. guix-data-service-activation)
  598. (service-extension account-service-type
  599. guix-data-service-account)
  600. (service-extension getmail-service-type
  601. guix-data-service-getmail-configuration)))
  602. (default-value
  603. (guix-data-service-configuration))
  604. (description
  605. "Run an instance of the Guix Data Service.")))