guix.scm 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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-authentication
  56. guix-build-coordinator-agent-configuration-systems
  57. guix-build-coordinator-agent-configuration-max-parallel-builds
  58. guix-build-coordinator-agent-configuration-max-1min-load-average
  59. guix-build-coordinator-agent-configuration-derivation-substitute-urls
  60. guix-build-coordinator-agent-configuration-non-derivation-substitute-urls
  61. guix-build-coordinator-agent-password-auth
  62. guix-build-coordinator-agent-password-auth?
  63. guix-build-coordinator-agent-password-auth-uuid
  64. guix-build-coordinator-agent-password-auth-password
  65. guix-build-coordinator-agent-password-file-auth
  66. guix-build-coordinator-agent-password-file-auth?
  67. guix-build-coordinator-agent-password-file-auth-uuid
  68. guix-build-coordinator-agent-password-file-auth-password-file
  69. guix-build-coordinator-agent-dynamic-auth
  70. guix-build-coordinator-agent-dynamic-auth?
  71. guix-build-coordinator-agent-dynamic-auth-agent-name
  72. guix-build-coordinator-agent-dynamic-auth-token
  73. guix-build-coordinator-agent-dynamic-auth-with-file
  74. guix-build-coordinator-agent-dynamic-auth-with-file?
  75. guix-build-coordinator-agent-dynamic-auth-with-file-agent-name
  76. guix-build-coordinator-agent-dynamic-auth-with-file-token-file
  77. guix-build-coordinator-agent-service-type
  78. guix-build-coordinator-queue-builds-configuration
  79. guix-build-coordinator-queue-builds-configuration?
  80. guix-build-coordinator-queue-builds-configuration-package
  81. guix-build-coordinator-queue-builds-configuration-user
  82. guix-build-coordinator-queue-builds-coordinator
  83. guix-build-coordinator-queue-builds-configuration-systems
  84. guix-build-coordinator-queue-builds-configuration-system-and-targets
  85. guix-build-coordinator-queue-builds-configuration-guix-data-service
  86. guix-build-coordinator-queue-builds-configuration-processed-commits-file
  87. guix-build-coordinator-queue-builds-service-type
  88. <guix-data-service-configuration>
  89. guix-data-service-configuration
  90. guix-data-service-configuration?
  91. guix-data-service-package
  92. guix-data-service-user
  93. guix-data-service-group
  94. guix-data-service-port
  95. guix-data-service-host
  96. guix-data-service-getmail-idle-mailboxes
  97. guix-data-service-commits-getmail-retriever-configuration
  98. guix-data-service-type))
  99. ;;;; Commentary:
  100. ;;;
  101. ;;; Services specifically related to GNU Guix.
  102. ;;;
  103. ;;;; Code:
  104. (define-record-type* <guix-build-coordinator-configuration>
  105. guix-build-coordinator-configuration make-guix-build-coordinator-configuration
  106. guix-build-coordinator-configuration?
  107. (package guix-build-coordinator-configuration-package
  108. (default guix-build-coordinator))
  109. (user guix-build-coordinator-configuration-user
  110. (default "guix-build-coordinator"))
  111. (group guix-build-coordinator-configuration-group
  112. (default "guix-build-coordinator"))
  113. (database-uri-string
  114. guix-build-coordinator-configuration-datastore-uri-string
  115. (default "sqlite:///var/lib/guix-build-coordinator/guix_build_coordinator.db"))
  116. (agent-communication-uri-string
  117. guix-build-coordinator-configuration-agent-communication-uri-string
  118. (default "http://0.0.0.0:8745"))
  119. (client-communication-uri-string
  120. guix-build-coordinator-configuration-client-communication-uri-string
  121. (default "http://127.0.0.1:8746"))
  122. (allocation-strategy
  123. guix-build-coordinator-configuration-allocation-strategy
  124. (default #~basic-build-allocation-strategy))
  125. (hooks guix-build-coordinator-configuration-hooks
  126. (default '()))
  127. (guile guix-build-coordinator-configuration-guile
  128. (default guile-3.0-latest)))
  129. (define-record-type* <guix-build-coordinator-agent-configuration>
  130. guix-build-coordinator-agent-configuration
  131. make-guix-build-coordinator-agent-configuration
  132. guix-build-coordinator-agent-configuration?
  133. (package guix-build-coordinator-agent-configuration-package
  134. (default guix-build-coordinator))
  135. (user guix-build-coordinator-agent-configuration-user
  136. (default "guix-build-coordinator-agent"))
  137. (coordinator guix-build-coordinator-agent-configuration-coordinator
  138. (default "http://localhost:8745"))
  139. (authentication guix-build-coordinator-agent-configuration-authentication)
  140. (systems guix-build-coordinator-agent-configuration-systems
  141. (default #f))
  142. (max-parallel-builds
  143. guix-build-coordinator-agent-configuration-max-parallel-builds
  144. (default 1))
  145. (max-1min-load-average
  146. guix-build-coordinator-agent-configuration-max-1min-load-average
  147. (default #f))
  148. (derivation-substitute-urls
  149. guix-build-coordinator-agent-configuration-derivation-substitute-urls
  150. (default #f))
  151. (non-derivation-substitute-urls
  152. guix-build-coordinator-agent-configuration-non-derivation-substitute-urls
  153. (default #f)))
  154. (define-record-type* <guix-build-coordinator-agent-password-auth>
  155. guix-build-coordinator-agent-password-auth
  156. make-guix-build-coordinator-agent-password-auth
  157. guix-build-coordinator-agent-password-auth?
  158. (uuid guix-build-coordinator-agent-password-auth-uuid)
  159. (password guix-build-coordinator-agent-password-auth-password))
  160. (define-record-type* <guix-build-coordinator-agent-password-file-auth>
  161. guix-build-coordinator-agent-password-file-auth
  162. make-guix-build-coordinator-agent-password-file-auth
  163. guix-build-coordinator-agent-password-file-auth?
  164. (uuid guix-build-coordinator-agent-password-file-auth-uuid)
  165. (password-file
  166. guix-build-coordinator-agent-password-file-auth-password-file))
  167. (define-record-type* <guix-build-coordinator-agent-dynamic-auth>
  168. guix-build-coordinator-agent-dynamic-auth
  169. make-guix-build-coordinator-agent-dynamic-auth
  170. guix-build-coordinator-agent-dynamic-auth?
  171. (agent-name guix-build-coordinator-agent-dynamic-auth-agent-name)
  172. (token guix-build-coordinator-agent-dynamic-auth-token))
  173. (define-record-type* <guix-build-coordinator-agent-dynamic-auth-with-file>
  174. guix-build-coordinator-agent-dynamic-auth-with-file
  175. make-guix-build-coordinator-agent-dynamic-auth-with-file
  176. guix-build-coordinator-agent-dynamic-auth-with-file?
  177. (agent-name guix-build-coordinator-agent-dynamic-auth-with-file-agent-name)
  178. (token-file guix-build-coordinator-agent-dynamic-auth-with-file-token-file))
  179. (define-record-type* <guix-build-coordinator-queue-builds-configuration>
  180. guix-build-coordinator-queue-builds-configuration
  181. make-guix-build-coordinator-queue-builds-configuration
  182. guix-build-coordinator-queue-builds-configuration?
  183. (package guix-build-coordinator-queue-builds-configuration-package
  184. (default guix-build-coordinator))
  185. (user guix-build-coordinator-queue-builds-configuration-user
  186. (default "guix-build-coordinator-queue-builds"))
  187. (coordinator guix-build-coordinator-queue-builds-coordinator
  188. (default "http://localhost:8746"))
  189. (systems guix-build-coordinator-queue-builds-configuration-systems
  190. (default #f))
  191. (systems-and-targets
  192. guix-build-coordinator-queue-builds-configuration-system-and-targets
  193. (default #f))
  194. (guix-data-service
  195. guix-build-coordinator-queue-builds-configuration-guix-data-service
  196. (default "https://data.guix.gnu.org"))
  197. (processed-commits-file
  198. guix-build-coordinator-queue-builds-configuration-processed-commits-file
  199. (default "/var/cache/guix-build-coordinator-queue-builds/processed-commits")))
  200. (define* (make-guix-build-coordinator-start-script database-uri-string
  201. allocation-strategy
  202. pid-file
  203. guix-build-coordinator-package
  204. #:key
  205. agent-communication-uri-string
  206. client-communication-uri-string
  207. (hooks '())
  208. (guile guile-3.0))
  209. (program-file
  210. "start-guix-build-coordinator"
  211. (with-extensions (cons guix-build-coordinator-package
  212. ;; This is a poorly constructed Guile load path,
  213. ;; since it contains things that aren't Guile
  214. ;; libraries, but it means that the Guile libraries
  215. ;; needed for the Guix Build Coordinator don't need
  216. ;; to be individually specified here.
  217. (append
  218. (map second (package-inputs
  219. guix-build-coordinator-package))
  220. (map second (package-propagated-inputs
  221. guix-build-coordinator-package))))
  222. #~(begin
  223. (use-modules (srfi srfi-1)
  224. (ice-9 match)
  225. (web uri)
  226. (prometheus)
  227. (guix-build-coordinator hooks)
  228. (guix-build-coordinator datastore)
  229. (guix-build-coordinator build-allocator)
  230. (guix-build-coordinator coordinator))
  231. (setvbuf (current-output-port) 'line)
  232. (setvbuf (current-error-port) 'line)
  233. (simple-format #t "starting the guix-build-coordinator:\n ~A\n"
  234. (current-filename))
  235. (let* ((metrics-registry (make-metrics-registry
  236. #:namespace
  237. "guixbuildcoordinator"))
  238. (datastore (database-uri->datastore
  239. #$database-uri-string
  240. #:metrics-registry metrics-registry))
  241. (hooks
  242. (list #$@(map (match-lambda
  243. ((name . hook-gexp)
  244. #~(cons '#$name #$hook-gexp)))
  245. hooks)))
  246. (hooks-with-defaults
  247. `(,@hooks
  248. ,@(remove (match-lambda
  249. ((name . _) (assq-ref hooks name)))
  250. %default-hooks)))
  251. (build-coordinator (make-build-coordinator
  252. #:datastore datastore
  253. #:hooks hooks-with-defaults
  254. #:metrics-registry metrics-registry
  255. #:allocation-strategy #$allocation-strategy)))
  256. (run-coordinator-service
  257. build-coordinator
  258. #:update-datastore? #t
  259. #:pid-file #$pid-file
  260. #:agent-communication-uri (string->uri
  261. #$agent-communication-uri-string)
  262. #:client-communication-uri (string->uri
  263. #$client-communication-uri-string)))))
  264. #:guile guile))
  265. (define (guix-build-coordinator-shepherd-services config)
  266. (match-record config <guix-build-coordinator-configuration>
  267. (package user group database-uri-string
  268. agent-communication-uri-string
  269. client-communication-uri-string
  270. allocation-strategy
  271. hooks
  272. guile)
  273. (list
  274. (shepherd-service
  275. (documentation "Guix Build Coordinator")
  276. (provision '(guix-build-coordinator))
  277. (requirement '(networking))
  278. (start #~(make-forkexec-constructor
  279. (list #$(make-guix-build-coordinator-start-script
  280. database-uri-string
  281. allocation-strategy
  282. "/var/run/guix-build-coordinator/pid"
  283. package
  284. #:agent-communication-uri-string
  285. agent-communication-uri-string
  286. #:client-communication-uri-string
  287. client-communication-uri-string
  288. #:hooks hooks
  289. #:guile guile))
  290. #:user #$user
  291. #:group #$group
  292. #:pid-file "/var/run/guix-build-coordinator/pid"
  293. ;; Allow time for migrations to run
  294. #:pid-file-timeout 60
  295. #:environment-variables
  296. `(,(string-append
  297. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  298. "LC_ALL=en_US.utf8"
  299. "PATH=/run/current-system/profile/bin") ; for hooks
  300. #:log-file "/var/log/guix-build-coordinator/coordinator.log"))
  301. (stop #~(make-kill-destructor))))))
  302. (define (guix-build-coordinator-activation config)
  303. #~(begin
  304. (use-modules (guix build utils))
  305. (define %user
  306. (getpw #$(guix-build-coordinator-configuration-user
  307. config)))
  308. (chmod "/var/lib/guix-build-coordinator" #o755)
  309. (mkdir-p "/var/log/guix-build-coordinator")
  310. ;; Allow writing the PID file
  311. (mkdir-p "/var/run/guix-build-coordinator")
  312. (chown "/var/run/guix-build-coordinator"
  313. (passwd:uid %user)
  314. (passwd:gid %user))))
  315. (define (guix-build-coordinator-account config)
  316. (match-record config <guix-build-coordinator-configuration>
  317. (user group)
  318. (list (user-group
  319. (name group)
  320. (system? #t))
  321. (user-account
  322. (name user)
  323. (group group)
  324. (system? #t)
  325. (comment "Guix Build Coordinator user")
  326. (home-directory "/var/lib/guix-build-coordinator")
  327. (shell (file-append shadow "/sbin/nologin"))))))
  328. (define guix-build-coordinator-service-type
  329. (service-type
  330. (name 'guix-build-coordinator)
  331. (extensions
  332. (list
  333. (service-extension shepherd-root-service-type
  334. guix-build-coordinator-shepherd-services)
  335. (service-extension activation-service-type
  336. guix-build-coordinator-activation)
  337. (service-extension account-service-type
  338. guix-build-coordinator-account)))
  339. (default-value
  340. (guix-build-coordinator-configuration))
  341. (description
  342. "Run an instance of the Guix Build Coordinator.")))
  343. (define (guix-build-coordinator-agent-shepherd-services config)
  344. (match-record config <guix-build-coordinator-agent-configuration>
  345. (package user coordinator authentication max-parallel-builds
  346. max-1min-load-average
  347. derivation-substitute-urls non-derivation-substitute-urls
  348. systems)
  349. (list
  350. (shepherd-service
  351. (documentation "Guix Build Coordinator Agent")
  352. (provision '(guix-build-coordinator-agent))
  353. (requirement '(networking))
  354. (start #~(make-forkexec-constructor
  355. (list #$(file-append package "/bin/guix-build-coordinator-agent")
  356. #$(string-append "--coordinator=" coordinator)
  357. #$@(match authentication
  358. (($ <guix-build-coordinator-agent-password-auth>
  359. uuid password)
  360. #~(#$(string-append "--uuid=" uuid)
  361. #$(string-append "--password=" password)))
  362. (($ <guix-build-coordinator-agent-password-file-auth>
  363. uuid password-file)
  364. #~(#$(string-append "--uuid=" uuid)
  365. #$(string-append "--password-file="
  366. password-file)))
  367. (($ <guix-build-coordinator-agent-dynamic-auth>
  368. agent-name token)
  369. #~(#$(string-append "--name=" agent-name)
  370. #$(string-append "--dynamic-auth-token=" token)))
  371. (($
  372. <guix-build-coordinator-agent-dynamic-auth-with-file>
  373. agent-name token-file)
  374. #~(#$(string-append "--name=" agent-name)
  375. #$(string-append "--dynamic-auth-token-file="
  376. token-file))))
  377. #$(simple-format #f "--max-parallel-builds=~A"
  378. max-parallel-builds)
  379. #$@(if max-1min-load-average
  380. #~(#$(simple-format #f "--max-1min-load-average=~A"
  381. max-1min-load-average))
  382. #~())
  383. #$@(if derivation-substitute-urls
  384. #~(#$(string-append
  385. "--derivation-substitute-urls="
  386. (string-join derivation-substitute-urls " ")))
  387. #~())
  388. #$@(if non-derivation-substitute-urls
  389. #~(#$(string-append
  390. "--non-derivation-substitute-urls="
  391. (string-join non-derivation-substitute-urls " ")))
  392. #~())
  393. #$@(map (lambda (system)
  394. (string-append "--system=" system))
  395. (or systems '())))
  396. #:user #$user
  397. #:environment-variables
  398. `(,(string-append
  399. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  400. ;; XDG_CACHE_HOME is used by Guix when caching narinfo files
  401. "XDG_CACHE_HOME=/var/cache/guix-build-coordinator-agent"
  402. "LC_ALL=en_US.utf8")
  403. #:log-file "/var/log/guix-build-coordinator/agent.log"))
  404. (stop #~(make-kill-destructor))))))
  405. (define (guix-build-coordinator-agent-activation config)
  406. #~(begin
  407. (use-modules (guix build utils))
  408. (define %user
  409. (getpw #$(guix-build-coordinator-agent-configuration-user
  410. config)))
  411. (mkdir-p "/var/log/guix-build-coordinator")
  412. ;; Create a cache directory for storing narinfo files if downloaded
  413. (mkdir-p "/var/cache/guix-build-coordinator-agent")
  414. (chown "/var/cache/guix-build-coordinator-agent"
  415. (passwd:uid %user)
  416. (passwd:gid %user))))
  417. (define (guix-build-coordinator-agent-account config)
  418. (list (user-account
  419. (name (guix-build-coordinator-agent-configuration-user config))
  420. (group "nogroup")
  421. (system? #t)
  422. (comment "Guix Build Coordinator agent user")
  423. (home-directory "/var/empty")
  424. (shell (file-append shadow "/sbin/nologin")))))
  425. (define guix-build-coordinator-agent-service-type
  426. (service-type
  427. (name 'guix-build-coordinator-agent)
  428. (extensions
  429. (list
  430. (service-extension shepherd-root-service-type
  431. guix-build-coordinator-agent-shepherd-services)
  432. (service-extension activation-service-type
  433. guix-build-coordinator-agent-activation)
  434. (service-extension account-service-type
  435. guix-build-coordinator-agent-account)))
  436. (description
  437. "Run a Guix Build Coordinator agent.")))
  438. (define (guix-build-coordinator-queue-builds-shepherd-services config)
  439. (match-record config <guix-build-coordinator-queue-builds-configuration>
  440. (package user coordinator systems systems-and-targets
  441. guix-data-service processed-commits-file)
  442. (list
  443. (shepherd-service
  444. (documentation "Guix Build Coordinator queue builds from Guix Data Service")
  445. (provision '(guix-build-coordinator-queue-builds))
  446. (requirement '(networking))
  447. (start
  448. #~(make-forkexec-constructor
  449. (list
  450. #$(file-append
  451. package
  452. "/bin/guix-build-coordinator-queue-builds-from-guix-data-service")
  453. #$(string-append "--coordinator=" coordinator)
  454. #$@(map (lambda (system)
  455. (string-append "--system=" system))
  456. (or systems '()))
  457. #$@(map (match-lambda
  458. ((system . target)
  459. (string-append "--system-and-target=" system "=" target)))
  460. (or systems-and-targets '()))
  461. #$@(if guix-data-service
  462. #~(#$(string-append "--guix-data-service=" guix-data-service))
  463. #~())
  464. #$@(if processed-commits-file
  465. #~(#$(string-append "--processed-commits-file="
  466. processed-commits-file))
  467. #~()))
  468. #:user #$user
  469. #:environment-variables
  470. `(,(string-append
  471. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  472. "LC_ALL=en_US.utf8")
  473. #:log-file "/var/log/guix-build-coordinator/queue-builds.log"))
  474. (stop #~(make-kill-destructor))))))
  475. (define (guix-build-coordinator-queue-builds-activation config)
  476. #~(begin
  477. (use-modules (guix build utils))
  478. (define %user
  479. (getpw #$(guix-build-coordinator-queue-builds-configuration-user
  480. config)))
  481. (mkdir-p "/var/log/guix-build-coordinator")
  482. ;; Allow writing the processed commits file
  483. (mkdir-p "/var/cache/guix-build-coordinator-queue-builds")
  484. (chown "/var/cache/guix-build-coordinator-queue-builds"
  485. (passwd:uid %user)
  486. (passwd:gid %user))))
  487. (define (guix-build-coordinator-queue-builds-account config)
  488. (list (user-account
  489. (name (guix-build-coordinator-queue-builds-configuration-user config))
  490. (group "nogroup")
  491. (system? #t)
  492. (comment "Guix Build Coordinator queue-builds user")
  493. (home-directory "/var/empty")
  494. (shell (file-append shadow "/sbin/nologin")))))
  495. (define guix-build-coordinator-queue-builds-service-type
  496. (service-type
  497. (name 'guix-build-coordinator-queue-builds)
  498. (extensions
  499. (list
  500. (service-extension shepherd-root-service-type
  501. guix-build-coordinator-queue-builds-shepherd-services)
  502. (service-extension activation-service-type
  503. guix-build-coordinator-queue-builds-activation)
  504. (service-extension account-service-type
  505. guix-build-coordinator-queue-builds-account)))
  506. (description
  507. "Run the guix-build-coordinator-queue-builds-from-guix-data-service
  508. script.
  509. This is a script to assist in having the Guix Build Coordinator build
  510. derivations stored in an instance of the Guix Data Service.")))
  511. ;;;
  512. ;;; Guix Data Service
  513. ;;;
  514. (define-record-type* <guix-data-service-configuration>
  515. guix-data-service-configuration make-guix-data-service-configuration
  516. guix-data-service-configuration?
  517. (package guix-data-service-package
  518. (default guix-data-service))
  519. (user guix-data-service-configuration-user
  520. (default "guix-data-service"))
  521. (group guix-data-service-configuration-group
  522. (default "guix-data-service"))
  523. (port guix-data-service-port
  524. (default 8765))
  525. (host guix-data-service-host
  526. (default "127.0.0.1"))
  527. (getmail-idle-mailboxes
  528. guix-data-service-getmail-idle-mailboxes
  529. (default #f))
  530. (commits-getmail-retriever-configuration
  531. guix-data-service-commits-getmail-retriever-configuration
  532. (default #f))
  533. (extra-options guix-data-service-extra-options
  534. (default '()))
  535. (extra-process-jobs-options
  536. guix-data-service-extra-process-jobs-options
  537. (default '())))
  538. (define (guix-data-service-profile-packages config)
  539. "Return the guix-data-service package, this will populate the
  540. ca-certificates.crt file in the system profile."
  541. (list
  542. (guix-data-service-package config)))
  543. (define (guix-data-service-shepherd-services config)
  544. (match-record config <guix-data-service-configuration>
  545. (package user group port host extra-options extra-process-jobs-options)
  546. (list
  547. (shepherd-service
  548. (documentation "Guix Data Service web server")
  549. (provision '(guix-data-service))
  550. (requirement '(postgres networking))
  551. (start #~(make-forkexec-constructor
  552. (list #$(file-append package
  553. "/bin/guix-data-service")
  554. "--pid-file=/var/run/guix-data-service/pid"
  555. #$(string-append "--port=" (number->string port))
  556. #$(string-append "--host=" host)
  557. ;; Perform any database migrations when the
  558. ;; service is started
  559. "--update-database"
  560. #$@extra-options)
  561. #:user #$user
  562. #:group #$group
  563. #:pid-file "/var/run/guix-data-service/pid"
  564. ;; Allow time for migrations to run
  565. #:pid-file-timeout 60
  566. #:environment-variables
  567. `(,(string-append
  568. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  569. "LC_ALL=en_US.UTF-8")
  570. #:log-file "/var/log/guix-data-service/web.log"))
  571. (stop #~(make-kill-destructor)))
  572. (shepherd-service
  573. (documentation "Guix Data Service process jobs")
  574. (provision '(guix-data-service-process-jobs))
  575. (requirement '(postgres
  576. networking
  577. ;; Require guix-data-service, as that the database
  578. ;; migrations are handled through this service
  579. guix-data-service))
  580. (start #~(make-forkexec-constructor
  581. (list
  582. #$(file-append package
  583. "/bin/guix-data-service-process-jobs")
  584. #$@extra-process-jobs-options)
  585. #:user #$user
  586. #:group #$group
  587. #:environment-variables
  588. `("HOME=/var/lib/guix-data-service"
  589. "GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt"
  590. ,(string-append
  591. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  592. "LC_ALL=en_US.UTF-8")
  593. #:log-file "/var/log/guix-data-service/process-jobs.log"))
  594. (stop #~(make-kill-destructor))))))
  595. (define (guix-data-service-activation config)
  596. #~(begin
  597. (use-modules (guix build utils))
  598. (define %user (getpw "guix-data-service"))
  599. (chmod "/var/lib/guix-data-service" #o755)
  600. (mkdir-p "/var/log/guix-data-service")
  601. ;; Allow writing the PID file
  602. (mkdir-p "/var/run/guix-data-service")
  603. (chown "/var/run/guix-data-service"
  604. (passwd:uid %user)
  605. (passwd:gid %user))))
  606. (define (guix-data-service-account config)
  607. (match-record config <guix-data-service-configuration>
  608. (user group)
  609. (list (user-group
  610. (name group)
  611. (system? #t))
  612. (user-account
  613. (name user)
  614. (group group)
  615. (system? #t)
  616. (comment "Guix Data Service user")
  617. (home-directory "/var/lib/guix-data-service")
  618. (shell (file-append shadow "/sbin/nologin"))))))
  619. (define (guix-data-service-getmail-configuration config)
  620. (match config
  621. (($ <guix-data-service-configuration> package user group
  622. port host
  623. #f #f)
  624. '())
  625. (($ <guix-data-service-configuration> package user group
  626. port host
  627. getmail-idle-mailboxes
  628. commits-getmail-retriever-configuration)
  629. (list
  630. (getmail-configuration
  631. (name 'guix-data-service)
  632. (user user)
  633. (group group)
  634. (directory "/var/lib/getmail/guix-data-service")
  635. (rcfile
  636. (getmail-configuration-file
  637. (retriever commits-getmail-retriever-configuration)
  638. (destination
  639. (getmail-destination-configuration
  640. (type "MDA_external")
  641. (path (file-append
  642. package
  643. "/bin/guix-data-service-process-branch-updated-email"))))
  644. (options
  645. (getmail-options-configuration
  646. (read-all #f)
  647. (delivered-to #f)
  648. (received #f)))))
  649. (idle getmail-idle-mailboxes))))))
  650. (define guix-data-service-type
  651. (service-type
  652. (name 'guix-data-service)
  653. (extensions
  654. (list
  655. (service-extension profile-service-type
  656. guix-data-service-profile-packages)
  657. (service-extension shepherd-root-service-type
  658. guix-data-service-shepherd-services)
  659. (service-extension activation-service-type
  660. guix-data-service-activation)
  661. (service-extension account-service-type
  662. guix-data-service-account)
  663. (service-extension getmail-service-type
  664. guix-data-service-getmail-configuration)))
  665. (default-value
  666. (guix-data-service-configuration))
  667. (description
  668. "Run an instance of the Guix Data Service.")))