guix.scm 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019, 2020, 2021, 2022 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-parallel-hooks
  49. guix-build-coordinator-configuration-guile
  50. guix-build-coordinator-configuration-extra-environment-variables
  51. guix-build-coordinator-service-type
  52. guix-build-coordinator-agent-configuration
  53. guix-build-coordinator-agent-configuration?
  54. guix-build-coordinator-agent-configuration-package
  55. guix-build-coordinator-agent-configuration-user
  56. guix-build-coordinator-agent-configuration-coordinator
  57. guix-build-coordinator-agent-configuration-authentication
  58. guix-build-coordinator-agent-configuration-systems
  59. guix-build-coordinator-agent-configuration-max-parallel-builds
  60. guix-build-coordinator-agent-configuration-max-parallel-uploads
  61. guix-build-coordinator-agent-configuration-max-allocated-builds
  62. guix-build-coordinator-agent-configuration-max-1min-load-average
  63. guix-build-coordinator-agent-configuration-derivation-substitute-urls
  64. guix-build-coordinator-agent-configuration-non-derivation-substitute-urls
  65. guix-build-coordinator-agent-password-auth
  66. guix-build-coordinator-agent-password-auth?
  67. guix-build-coordinator-agent-password-auth-uuid
  68. guix-build-coordinator-agent-password-auth-password
  69. guix-build-coordinator-agent-password-file-auth
  70. guix-build-coordinator-agent-password-file-auth?
  71. guix-build-coordinator-agent-password-file-auth-uuid
  72. guix-build-coordinator-agent-password-file-auth-password-file
  73. guix-build-coordinator-agent-dynamic-auth
  74. guix-build-coordinator-agent-dynamic-auth?
  75. guix-build-coordinator-agent-dynamic-auth-agent-name
  76. guix-build-coordinator-agent-dynamic-auth-token
  77. guix-build-coordinator-agent-dynamic-auth-with-file
  78. guix-build-coordinator-agent-dynamic-auth-with-file?
  79. guix-build-coordinator-agent-dynamic-auth-with-file-agent-name
  80. guix-build-coordinator-agent-dynamic-auth-with-file-token-file
  81. guix-build-coordinator-agent-service-type
  82. guix-build-coordinator-queue-builds-configuration
  83. guix-build-coordinator-queue-builds-configuration?
  84. guix-build-coordinator-queue-builds-configuration-package
  85. guix-build-coordinator-queue-builds-configuration-user
  86. guix-build-coordinator-queue-builds-coordinator
  87. guix-build-coordinator-queue-builds-configuration-systems
  88. guix-build-coordinator-queue-builds-configuration-system-and-targets
  89. guix-build-coordinator-queue-builds-configuration-guix-data-service
  90. guix-build-coordinator-queue-builds-configuration-guix-data-service-build-server-id
  91. guix-build-coordinator-queue-builds-configuration-processed-commits-file
  92. guix-build-coordinator-queue-builds-service-type
  93. <guix-data-service-configuration>
  94. guix-data-service-configuration
  95. guix-data-service-configuration?
  96. guix-data-service-package
  97. guix-data-service-user
  98. guix-data-service-group
  99. guix-data-service-port
  100. guix-data-service-host
  101. guix-data-service-getmail-idle-mailboxes
  102. guix-data-service-commits-getmail-retriever-configuration
  103. guix-data-service-type
  104. nar-herder-service-type
  105. nar-herder-configuration
  106. nar-herder-configuration?
  107. nar-herder-configuration-package
  108. nar-herder-configuration-user
  109. nar-herder-configuration-group
  110. nar-herder-configuration-mirror
  111. nar-herder-configuration-database
  112. nar-herder-configuration-database-dump
  113. nar-herder-configuration-host
  114. nar-herder-configuration-port
  115. nar-herder-configuration-storage
  116. nar-herder-configuration-storage-limit
  117. nar-herder-configuration-storage-nar-removal-criteria
  118. nar-herder-configuration-log-level
  119. nar-herder-configuration-cached-compressions
  120. nar-herder-configuration-cached-compression-min-uses
  121. nar-herder-configuration-cached-compression-workers
  122. nar-herder-configuration-cached-compression-nar-source
  123. nar-herder-configuration-extra-environment-variables
  124. nar-herder-cached-compression-configuration
  125. nar-herder-cached-compression-configuration?
  126. nar-herder-cached-compression-configuration-type
  127. nar-herder-cached-compression-configuration-level
  128. nar-herder-cached-compression-configuration-directory
  129. nar-herder-cached-compression-configuration-directory-max-size))
  130. ;;;; Commentary:
  131. ;;;
  132. ;;; Services specifically related to GNU Guix.
  133. ;;;
  134. ;;;; Code:
  135. (define-record-type* <guix-build-coordinator-configuration>
  136. guix-build-coordinator-configuration make-guix-build-coordinator-configuration
  137. guix-build-coordinator-configuration?
  138. (package guix-build-coordinator-configuration-package
  139. (default guix-build-coordinator))
  140. (user guix-build-coordinator-configuration-user
  141. (default "guix-build-coordinator"))
  142. (group guix-build-coordinator-configuration-group
  143. (default "guix-build-coordinator"))
  144. (database-uri-string
  145. guix-build-coordinator-configuration-datastore-uri-string
  146. (default "sqlite:///var/lib/guix-build-coordinator/guix_build_coordinator.db"))
  147. (agent-communication-uri-string
  148. guix-build-coordinator-configuration-agent-communication-uri-string
  149. (default "http://0.0.0.0:8745"))
  150. (client-communication-uri-string
  151. guix-build-coordinator-configuration-client-communication-uri-string
  152. (default "http://127.0.0.1:8746"))
  153. (allocation-strategy
  154. guix-build-coordinator-configuration-allocation-strategy
  155. (default #~basic-build-allocation-strategy))
  156. (hooks guix-build-coordinator-configuration-hooks
  157. (default '()))
  158. (parallel-hooks guix-build-coordinator-configuration-parallel-hooks
  159. (default '()))
  160. (guile guix-build-coordinator-configuration-guile
  161. (default guile-3.0-latest))
  162. (extra-environment-variables
  163. guix-build-coordinator-configuration-extra-environment-variables
  164. (default '())))
  165. (define-record-type* <guix-build-coordinator-agent-configuration>
  166. guix-build-coordinator-agent-configuration
  167. make-guix-build-coordinator-agent-configuration
  168. guix-build-coordinator-agent-configuration?
  169. (package guix-build-coordinator-agent-configuration-package
  170. (default guix-build-coordinator/agent-only))
  171. (user guix-build-coordinator-agent-configuration-user
  172. (default "guix-build-coordinator-agent"))
  173. (coordinator guix-build-coordinator-agent-configuration-coordinator
  174. (default "http://localhost:8745"))
  175. (authentication guix-build-coordinator-agent-configuration-authentication)
  176. (systems guix-build-coordinator-agent-configuration-systems
  177. (default #f))
  178. (max-parallel-builds
  179. guix-build-coordinator-agent-configuration-max-parallel-builds
  180. (default 1))
  181. (max-parallel-uploads
  182. guix-build-coordinator-agent-configuration-max-parallel-uploads
  183. (default 1))
  184. (max-allocated-builds
  185. guix-build-coordinator-agent-configuration-max-allocated-builds
  186. (default #f))
  187. (max-1min-load-average
  188. guix-build-coordinator-agent-configuration-max-1min-load-average
  189. (default #f))
  190. (derivation-substitute-urls
  191. guix-build-coordinator-agent-configuration-derivation-substitute-urls
  192. (default #f))
  193. (non-derivation-substitute-urls
  194. guix-build-coordinator-agent-configuration-non-derivation-substitute-urls
  195. (default #f)))
  196. (define-record-type* <guix-build-coordinator-agent-password-auth>
  197. guix-build-coordinator-agent-password-auth
  198. make-guix-build-coordinator-agent-password-auth
  199. guix-build-coordinator-agent-password-auth?
  200. (uuid guix-build-coordinator-agent-password-auth-uuid)
  201. (password guix-build-coordinator-agent-password-auth-password))
  202. (define-record-type* <guix-build-coordinator-agent-password-file-auth>
  203. guix-build-coordinator-agent-password-file-auth
  204. make-guix-build-coordinator-agent-password-file-auth
  205. guix-build-coordinator-agent-password-file-auth?
  206. (uuid guix-build-coordinator-agent-password-file-auth-uuid)
  207. (password-file
  208. guix-build-coordinator-agent-password-file-auth-password-file))
  209. (define-record-type* <guix-build-coordinator-agent-dynamic-auth>
  210. guix-build-coordinator-agent-dynamic-auth
  211. make-guix-build-coordinator-agent-dynamic-auth
  212. guix-build-coordinator-agent-dynamic-auth?
  213. (agent-name guix-build-coordinator-agent-dynamic-auth-agent-name)
  214. (token guix-build-coordinator-agent-dynamic-auth-token))
  215. (define-record-type* <guix-build-coordinator-agent-dynamic-auth-with-file>
  216. guix-build-coordinator-agent-dynamic-auth-with-file
  217. make-guix-build-coordinator-agent-dynamic-auth-with-file
  218. guix-build-coordinator-agent-dynamic-auth-with-file?
  219. (agent-name guix-build-coordinator-agent-dynamic-auth-with-file-agent-name)
  220. (token-file guix-build-coordinator-agent-dynamic-auth-with-file-token-file))
  221. (define-record-type* <guix-build-coordinator-queue-builds-configuration>
  222. guix-build-coordinator-queue-builds-configuration
  223. make-guix-build-coordinator-queue-builds-configuration
  224. guix-build-coordinator-queue-builds-configuration?
  225. (package guix-build-coordinator-queue-builds-configuration-package
  226. (default guix-build-coordinator))
  227. (user guix-build-coordinator-queue-builds-configuration-user
  228. (default "guix-build-coordinator-queue-builds"))
  229. (coordinator guix-build-coordinator-queue-builds-coordinator
  230. (default "http://localhost:8746"))
  231. (systems guix-build-coordinator-queue-builds-configuration-systems
  232. (default #f))
  233. (systems-and-targets
  234. guix-build-coordinator-queue-builds-configuration-system-and-targets
  235. (default #f))
  236. (guix-data-service
  237. guix-build-coordinator-queue-builds-configuration-guix-data-service
  238. (default "https://data.guix.gnu.org"))
  239. (guix-data-service-build-server-id
  240. guix-build-coordinator-queue-builds-configuration-guix-data-service-build-server-id
  241. (default #f))
  242. (processed-commits-file
  243. guix-build-coordinator-queue-builds-configuration-processed-commits-file
  244. (default "/var/cache/guix-build-coordinator-queue-builds/processed-commits")))
  245. (define* (make-guix-build-coordinator-start-script database-uri-string
  246. allocation-strategy
  247. pid-file
  248. guix-build-coordinator-package
  249. #:key
  250. agent-communication-uri-string
  251. client-communication-uri-string
  252. (hooks '())
  253. (parallel-hooks '())
  254. (guile guile-3.0))
  255. (program-file
  256. "start-guix-build-coordinator"
  257. (with-extensions (cons guix-build-coordinator-package
  258. ;; This is a poorly constructed Guile load path,
  259. ;; since it contains things that aren't Guile
  260. ;; libraries, but it means that the Guile libraries
  261. ;; needed for the Guix Build Coordinator don't need
  262. ;; to be individually specified here.
  263. (append
  264. (map second (package-inputs
  265. guix-build-coordinator-package))
  266. (map second (package-propagated-inputs
  267. guix-build-coordinator-package))))
  268. #~(begin
  269. (use-modules (srfi srfi-1)
  270. (ice-9 match)
  271. (web uri)
  272. (prometheus)
  273. (guix-build-coordinator hooks)
  274. (guix-build-coordinator datastore)
  275. (guix-build-coordinator build-allocator)
  276. (guix-build-coordinator coordinator))
  277. (setvbuf (current-output-port) 'line)
  278. (setvbuf (current-error-port) 'line)
  279. (simple-format #t "starting the guix-build-coordinator:\n ~A\n"
  280. (current-filename))
  281. (let* ((hooks
  282. (list #$@(map (match-lambda
  283. ((name . hook-gexp)
  284. #~(cons '#$name #$hook-gexp)))
  285. hooks)))
  286. (hooks-with-defaults
  287. `(,@hooks
  288. ,@(remove (match-lambda
  289. ((name . _) (assq-ref hooks name)))
  290. %default-hooks)))
  291. (build-coordinator (make-build-coordinator
  292. #:database-uri-string #$database-uri-string
  293. #:hooks hooks-with-defaults
  294. #:allocation-strategy #$allocation-strategy)))
  295. (run-coordinator-service
  296. build-coordinator
  297. #:update-datastore? #t
  298. #:pid-file #$pid-file
  299. #:agent-communication-uri (string->uri
  300. #$agent-communication-uri-string)
  301. #:client-communication-uri (string->uri
  302. #$client-communication-uri-string)
  303. #:parallel-hooks (list #$@(map (match-lambda
  304. ((name . val)
  305. #~(cons '#$name #$val)))
  306. parallel-hooks))))))
  307. #:guile guile))
  308. (define (guix-build-coordinator-shepherd-services config)
  309. (match-record config <guix-build-coordinator-configuration>
  310. (package user group database-uri-string
  311. agent-communication-uri-string
  312. client-communication-uri-string
  313. allocation-strategy
  314. hooks
  315. parallel-hooks
  316. guile
  317. extra-environment-variables)
  318. (list
  319. (shepherd-service
  320. (documentation "Guix Build Coordinator")
  321. (provision '(guix-build-coordinator))
  322. (requirement '(networking))
  323. (start #~(lambda args
  324. (parameterize ((%current-logfile-date-format ""))
  325. (apply
  326. (make-forkexec-constructor
  327. (list #$(make-guix-build-coordinator-start-script
  328. database-uri-string
  329. allocation-strategy
  330. "/var/run/guix-build-coordinator/pid"
  331. package
  332. #:agent-communication-uri-string
  333. agent-communication-uri-string
  334. #:client-communication-uri-string
  335. client-communication-uri-string
  336. #:hooks hooks
  337. #:parallel-hooks parallel-hooks
  338. #:guile guile))
  339. #:user #$user
  340. #:group #$group
  341. #:pid-file "/var/run/guix-build-coordinator/pid"
  342. ;; Allow time for migrations to run
  343. #:pid-file-timeout 60
  344. #:environment-variables
  345. `(,(string-append
  346. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  347. "LC_ALL=en_US.utf8"
  348. "PATH=/run/current-system/profile/bin" ; for hooks
  349. #$@extra-environment-variables)
  350. #:log-file "/var/log/guix-build-coordinator/coordinator.log")
  351. args))))
  352. (stop #~(make-kill-destructor))
  353. (modules
  354. `((shepherd comm)
  355. ,@%default-modules))))))
  356. (define (guix-build-coordinator-activation config)
  357. #~(begin
  358. (use-modules (guix build utils))
  359. (define %user
  360. (getpw #$(guix-build-coordinator-configuration-user
  361. config)))
  362. (chmod "/var/lib/guix-build-coordinator" #o755)
  363. (mkdir-p "/var/log/guix-build-coordinator")
  364. ;; Allow writing the PID file
  365. (mkdir-p "/var/run/guix-build-coordinator")
  366. (chown "/var/run/guix-build-coordinator"
  367. (passwd:uid %user)
  368. (passwd:gid %user))))
  369. (define (guix-build-coordinator-account config)
  370. (match-record config <guix-build-coordinator-configuration>
  371. (user group)
  372. (list (user-group
  373. (name group)
  374. (system? #t))
  375. (user-account
  376. (name user)
  377. (group group)
  378. (system? #t)
  379. (comment "Guix Build Coordinator user")
  380. (home-directory "/var/lib/guix-build-coordinator")
  381. (shell (file-append shadow "/sbin/nologin"))))))
  382. (define guix-build-coordinator-service-type
  383. (service-type
  384. (name 'guix-build-coordinator)
  385. (extensions
  386. (list
  387. (service-extension shepherd-root-service-type
  388. guix-build-coordinator-shepherd-services)
  389. (service-extension activation-service-type
  390. guix-build-coordinator-activation)
  391. (service-extension account-service-type
  392. guix-build-coordinator-account)))
  393. (default-value
  394. (guix-build-coordinator-configuration))
  395. (description
  396. "Run an instance of the Guix Build Coordinator.")))
  397. (define (guix-build-coordinator-agent-shepherd-services config)
  398. (match-record config <guix-build-coordinator-agent-configuration>
  399. (package user coordinator authentication
  400. max-parallel-builds max-parallel-uploads
  401. max-allocated-builds max-1min-load-average
  402. derivation-substitute-urls non-derivation-substitute-urls
  403. systems)
  404. (list
  405. (shepherd-service
  406. (documentation "Guix Build Coordinator Agent")
  407. (provision '(guix-build-coordinator-agent))
  408. (requirement '(networking))
  409. (start
  410. #~(lambda _
  411. (parameterize ((%current-logfile-date-format ""))
  412. (fork+exec-command
  413. (list #$(file-append package "/bin/guix-build-coordinator-agent")
  414. #$(string-append "--coordinator=" coordinator)
  415. #$@(match authentication
  416. (($ <guix-build-coordinator-agent-password-auth>
  417. uuid password)
  418. #~(#$(string-append "--uuid=" uuid)
  419. #$(string-append "--password=" password)))
  420. (($ <guix-build-coordinator-agent-password-file-auth>
  421. uuid password-file)
  422. #~(#$(string-append "--uuid=" uuid)
  423. #$(string-append "--password-file="
  424. password-file)))
  425. (($ <guix-build-coordinator-agent-dynamic-auth>
  426. agent-name token)
  427. #~(#$(string-append "--name=" agent-name)
  428. #$(string-append "--dynamic-auth-token=" token)))
  429. (($
  430. <guix-build-coordinator-agent-dynamic-auth-with-file>
  431. agent-name token-file)
  432. #~(#$(string-append "--name=" agent-name)
  433. #$(string-append "--dynamic-auth-token-file="
  434. token-file))))
  435. #$(simple-format #f "--max-parallel-builds=~A"
  436. max-parallel-builds)
  437. #$@(if max-parallel-uploads
  438. #~(#$(simple-format #f "--max-parallel-uploads=~A"
  439. max-parallel-uploads))
  440. #~())
  441. #$@(if max-allocated-builds
  442. #~(#$(simple-format #f "--max-allocated-builds=~A"
  443. max-allocated-builds))
  444. #~())
  445. #$@(if max-1min-load-average
  446. #~(#$(simple-format #f "--max-1min-load-average=~A"
  447. max-1min-load-average))
  448. #~())
  449. #$@(if derivation-substitute-urls
  450. #~(#$(string-append
  451. "--derivation-substitute-urls="
  452. (string-join derivation-substitute-urls " ")))
  453. #~())
  454. #$@(if non-derivation-substitute-urls
  455. #~(#$(string-append
  456. "--non-derivation-substitute-urls="
  457. (string-join non-derivation-substitute-urls " ")))
  458. #~())
  459. #$@(map (lambda (system)
  460. (string-append "--system=" system))
  461. (or systems '())))
  462. #:user #$user
  463. #:environment-variables
  464. `(,(string-append
  465. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  466. ;; XDG_CACHE_HOME is used by Guix when caching narinfo files
  467. "XDG_CACHE_HOME=/var/cache/guix-build-coordinator-agent"
  468. "LC_ALL=en_US.utf8")
  469. #:log-file "/var/log/guix-build-coordinator/agent.log"))))
  470. (stop #~(make-kill-destructor))
  471. (modules
  472. `((shepherd comm)
  473. ,@%default-modules))))))
  474. (define (guix-build-coordinator-agent-activation config)
  475. #~(begin
  476. (use-modules (guix build utils))
  477. (define %user
  478. (getpw #$(guix-build-coordinator-agent-configuration-user
  479. config)))
  480. (mkdir-p "/var/log/guix-build-coordinator")
  481. ;; Create a cache directory for storing narinfo files if downloaded
  482. (mkdir-p "/var/cache/guix-build-coordinator-agent")
  483. (chown "/var/cache/guix-build-coordinator-agent"
  484. (passwd:uid %user)
  485. (passwd:gid %user))))
  486. (define (guix-build-coordinator-agent-account config)
  487. (list (user-account
  488. (name (guix-build-coordinator-agent-configuration-user config))
  489. (group "nogroup")
  490. (system? #t)
  491. (comment "Guix Build Coordinator agent user")
  492. (home-directory "/var/empty")
  493. (shell (file-append shadow "/sbin/nologin")))))
  494. (define guix-build-coordinator-agent-service-type
  495. (service-type
  496. (name 'guix-build-coordinator-agent)
  497. (extensions
  498. (list
  499. (service-extension shepherd-root-service-type
  500. guix-build-coordinator-agent-shepherd-services)
  501. (service-extension activation-service-type
  502. guix-build-coordinator-agent-activation)
  503. (service-extension account-service-type
  504. guix-build-coordinator-agent-account)))
  505. (description
  506. "Run a Guix Build Coordinator agent.")))
  507. (define (guix-build-coordinator-queue-builds-shepherd-services config)
  508. (match-record config <guix-build-coordinator-queue-builds-configuration>
  509. (package user coordinator systems systems-and-targets
  510. guix-data-service
  511. guix-data-service-build-server-id
  512. processed-commits-file)
  513. (list
  514. (shepherd-service
  515. (documentation "Guix Build Coordinator queue builds from Guix Data Service")
  516. (provision '(guix-build-coordinator-queue-builds))
  517. (requirement '(networking))
  518. (start
  519. #~(lambda _
  520. (parameterize ((%current-logfile-date-format ""))
  521. (fork+exec-command
  522. (list
  523. #$(file-append
  524. package
  525. "/bin/guix-build-coordinator-queue-builds-from-guix-data-service")
  526. #$(string-append "--coordinator=" coordinator)
  527. #$@(map (lambda (system)
  528. (string-append "--system=" system))
  529. (or systems '()))
  530. #$@(map (match-lambda
  531. ((system . target)
  532. (string-append "--system-and-target=" system "=" target)))
  533. (or systems-and-targets '()))
  534. #$@(if guix-data-service
  535. #~(#$(string-append "--guix-data-service=" guix-data-service))
  536. #~())
  537. #$@(if guix-data-service-build-server-id
  538. #~(#$(simple-format
  539. #f
  540. "--guix-data-service-build-server-id=~A"
  541. guix-data-service-build-server-id))
  542. #~())
  543. #$@(if processed-commits-file
  544. #~(#$(string-append "--processed-commits-file="
  545. processed-commits-file))
  546. #~()))
  547. #:user #$user
  548. #:environment-variables
  549. `(,(string-append
  550. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  551. "LC_ALL=en_US.utf8")
  552. #:log-file "/var/log/guix-build-coordinator/queue-builds.log"))))
  553. (stop #~(make-kill-destructor))
  554. (modules
  555. `((shepherd comm)
  556. ,@%default-modules))))))
  557. (define (guix-build-coordinator-queue-builds-activation config)
  558. #~(begin
  559. (use-modules (guix build utils))
  560. (define %user
  561. (getpw #$(guix-build-coordinator-queue-builds-configuration-user
  562. config)))
  563. (mkdir-p "/var/log/guix-build-coordinator")
  564. ;; Allow writing the processed commits file
  565. (mkdir-p "/var/cache/guix-build-coordinator-queue-builds")
  566. (chown "/var/cache/guix-build-coordinator-queue-builds"
  567. (passwd:uid %user)
  568. (passwd:gid %user))))
  569. (define (guix-build-coordinator-queue-builds-account config)
  570. (list (user-account
  571. (name (guix-build-coordinator-queue-builds-configuration-user config))
  572. (group "nogroup")
  573. (system? #t)
  574. (comment "Guix Build Coordinator queue-builds user")
  575. (home-directory "/var/empty")
  576. (shell (file-append shadow "/sbin/nologin")))))
  577. (define guix-build-coordinator-queue-builds-service-type
  578. (service-type
  579. (name 'guix-build-coordinator-queue-builds)
  580. (extensions
  581. (list
  582. (service-extension shepherd-root-service-type
  583. guix-build-coordinator-queue-builds-shepherd-services)
  584. (service-extension activation-service-type
  585. guix-build-coordinator-queue-builds-activation)
  586. (service-extension account-service-type
  587. guix-build-coordinator-queue-builds-account)))
  588. (description
  589. "Run the guix-build-coordinator-queue-builds-from-guix-data-service
  590. script.
  591. This is a script to assist in having the Guix Build Coordinator build
  592. derivations stored in an instance of the Guix Data Service.")))
  593. ;;;
  594. ;;; Guix Data Service
  595. ;;;
  596. (define-record-type* <guix-data-service-configuration>
  597. guix-data-service-configuration make-guix-data-service-configuration
  598. guix-data-service-configuration?
  599. (package guix-data-service-package
  600. (default guix-data-service))
  601. (user guix-data-service-configuration-user
  602. (default "guix-data-service"))
  603. (group guix-data-service-configuration-group
  604. (default "guix-data-service"))
  605. (port guix-data-service-port
  606. (default 8765))
  607. (host guix-data-service-host
  608. (default "127.0.0.1"))
  609. (getmail-idle-mailboxes
  610. guix-data-service-getmail-idle-mailboxes
  611. (default #f))
  612. (commits-getmail-retriever-configuration
  613. guix-data-service-commits-getmail-retriever-configuration
  614. (default #f))
  615. (extra-options guix-data-service-extra-options
  616. (default '()))
  617. (extra-process-jobs-options
  618. guix-data-service-extra-process-jobs-options
  619. (default '())))
  620. (define (guix-data-service-profile-packages config)
  621. "Return the guix-data-service package, this will populate the
  622. ca-certificates.crt file in the system profile."
  623. (list
  624. (guix-data-service-package config)))
  625. (define (guix-data-service-shepherd-services config)
  626. (match-record config <guix-data-service-configuration>
  627. (package user group port host extra-options extra-process-jobs-options)
  628. (list
  629. (shepherd-service
  630. (documentation "Guix Data Service web server")
  631. (provision '(guix-data-service))
  632. (requirement '(postgres networking))
  633. (start #~(make-forkexec-constructor
  634. (list #$(file-append package
  635. "/bin/guix-data-service")
  636. "--pid-file=/var/run/guix-data-service/pid"
  637. #$(string-append "--port=" (number->string port))
  638. #$(string-append "--host=" host)
  639. ;; Perform any database migrations when the
  640. ;; service is started
  641. "--update-database"
  642. #$@extra-options)
  643. #:user #$user
  644. #:group #$group
  645. #:pid-file "/var/run/guix-data-service/pid"
  646. #:environment-variables
  647. `(,(string-append
  648. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  649. "LC_ALL=en_US.UTF-8")
  650. #:log-file "/var/log/guix-data-service/web.log"))
  651. (stop #~(make-kill-destructor)))
  652. (shepherd-service
  653. (documentation "Guix Data Service process jobs")
  654. (provision '(guix-data-service-process-jobs))
  655. (requirement '(postgres
  656. networking
  657. ;; Require guix-data-service, as that the database
  658. ;; migrations are handled through this service
  659. guix-data-service))
  660. (start #~(make-forkexec-constructor
  661. (list
  662. #$(file-append package
  663. "/bin/guix-data-service-process-jobs")
  664. #$@extra-process-jobs-options)
  665. #:user #$user
  666. #:group #$group
  667. #:environment-variables
  668. `("HOME=/var/lib/guix-data-service"
  669. "GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt"
  670. ,(string-append
  671. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  672. "LC_ALL=en_US.UTF-8")
  673. #:log-file "/var/log/guix-data-service/process-jobs.log"))
  674. (stop #~(make-kill-destructor))))))
  675. (define (guix-data-service-activation config)
  676. #~(begin
  677. (use-modules (guix build utils))
  678. (define %user (getpw "guix-data-service"))
  679. (chmod "/var/lib/guix-data-service" #o755)
  680. (mkdir-p "/var/log/guix-data-service")
  681. ;; Allow writing the PID file
  682. (mkdir-p "/var/run/guix-data-service")
  683. (chown "/var/run/guix-data-service"
  684. (passwd:uid %user)
  685. (passwd:gid %user))))
  686. (define (guix-data-service-account config)
  687. (match-record config <guix-data-service-configuration>
  688. (user group)
  689. (list (user-group
  690. (name group)
  691. (system? #t))
  692. (user-account
  693. (name user)
  694. (group group)
  695. (system? #t)
  696. (comment "Guix Data Service user")
  697. (home-directory "/var/lib/guix-data-service")
  698. (shell (file-append shadow "/sbin/nologin"))))))
  699. (define (guix-data-service-getmail-configuration config)
  700. (match config
  701. (($ <guix-data-service-configuration> package user group
  702. port host
  703. #f #f)
  704. '())
  705. (($ <guix-data-service-configuration> package user group
  706. port host
  707. getmail-idle-mailboxes
  708. commits-getmail-retriever-configuration)
  709. (list
  710. (getmail-configuration
  711. (name 'guix-data-service)
  712. (user user)
  713. (group group)
  714. (directory "/var/lib/getmail/guix-data-service")
  715. (rcfile
  716. (getmail-configuration-file
  717. (retriever commits-getmail-retriever-configuration)
  718. (destination
  719. (getmail-destination-configuration
  720. (type "MDA_external")
  721. (path (file-append
  722. package
  723. "/bin/guix-data-service-process-branch-updated-email"))))
  724. (options
  725. (getmail-options-configuration
  726. (read-all #f)
  727. (delivered-to #f)
  728. (received #f)))))
  729. (idle getmail-idle-mailboxes))))))
  730. (define guix-data-service-type
  731. (service-type
  732. (name 'guix-data-service)
  733. (extensions
  734. (list
  735. (service-extension profile-service-type
  736. guix-data-service-profile-packages)
  737. (service-extension shepherd-root-service-type
  738. guix-data-service-shepherd-services)
  739. (service-extension activation-service-type
  740. guix-data-service-activation)
  741. (service-extension account-service-type
  742. guix-data-service-account)
  743. (service-extension getmail-service-type
  744. guix-data-service-getmail-configuration)))
  745. (default-value
  746. (guix-data-service-configuration))
  747. (description
  748. "Run an instance of the Guix Data Service.")))
  749. ;;;
  750. ;;; Nar Herder
  751. ;;;
  752. (define-record-type* <nar-herder-configuration>
  753. nar-herder-configuration make-nar-herder-configuration
  754. nar-herder-configuration?
  755. (package nar-herder-configuration-package
  756. (default nar-herder))
  757. (user nar-herder-configuration-user
  758. (default "nar-herder"))
  759. (group nar-herder-configuration-group
  760. (default "nar-herder"))
  761. (mirror nar-herder-configuration-mirror
  762. (default #f))
  763. (database nar-herder-configuration-database
  764. (default "/var/lib/nar-herder/nar_herder.db"))
  765. (database-dump nar-herder-configuration-database-dump
  766. (default "/var/lib/nar-herder/nar_herder_dump.db"))
  767. (host nar-herder-configuration-host
  768. (default "127.0.0.1"))
  769. (port nar-herder-configuration-port
  770. (default 8734))
  771. (storage nar-herder-configuration-storage
  772. (default #f))
  773. (storage-limit nar-herder-configuration-storage-limit
  774. (default "none"))
  775. (storage-nar-removal-criteria
  776. nar-herder-configuration-storage-nar-removal-criteria
  777. (default '()))
  778. (ttl nar-herder-configuration-ttl
  779. (default #f))
  780. (negative-ttl nar-herder-configuration-negative-ttl
  781. (default #f))
  782. (log-level nar-herder-configuration-log-level
  783. (default 'DEBUG))
  784. (cached-compressions
  785. nar-herder-configuration-cached-compressions
  786. (default '()))
  787. (cached-compression-min-uses
  788. nar-herder-configuration-cached-compression-min-uses
  789. (default 3))
  790. (cached-compression-workers
  791. nar-herder-configuration-cached-compression-workers
  792. (default 2))
  793. (cached-compression-nar-source
  794. nar-herder-configuration-cached-compression-nar-source
  795. (default #f))
  796. (extra-environment-variables
  797. nar-herder-configuration-extra-environment-variables
  798. (default '())))
  799. (define-record-type* <nar-herder-cached-compression-configuration>
  800. nar-herder-cached-compression-configuration
  801. make-nar-herder-cached-compression-configuration
  802. nar-herder-cached-compression-configuration?
  803. (type nar-herder-cached-compression-configuration-type)
  804. (level nar-herder-cached-compression-configuration-level
  805. (default #f))
  806. (directory nar-herder-cached-compression-configuration-directory
  807. (default #f))
  808. (directory-max-size
  809. nar-herder-cached-compression-configuration-directory-max-size
  810. (default #f)))
  811. (define (nar-herder-shepherd-services config)
  812. (define (cached-compression-configuration->options cached-compression)
  813. (match-record
  814. cached-compression
  815. <nar-herder-cached-compression-configuration>
  816. (type level directory directory-max-size)
  817. `(,(simple-format #f "--enable-cached-compression=~A~A"
  818. type
  819. (if level
  820. (simple-format #f ":~A" level)
  821. ""))
  822. ,@(if directory
  823. (list
  824. (simple-format #f "--cached-compression-directory=~A=~A"
  825. type
  826. directory))
  827. '())
  828. ,@(if directory-max-size
  829. (list
  830. (simple-format #f "--cached-compression-directory-max-size=~A=~A"
  831. type
  832. directory-max-size))
  833. '()))))
  834. (match-record config <nar-herder-configuration>
  835. (package user group
  836. mirror
  837. database database-dump
  838. host port
  839. storage storage-limit storage-nar-removal-criteria
  840. ttl negative-ttl log-level
  841. cached-compressions cached-compression-min-uses
  842. cached-compression-workers cached-compression-nar-source
  843. extra-environment-variables)
  844. (unless (or mirror storage)
  845. (error "nar-herder: mirror or storage must be set"))
  846. (list
  847. (shepherd-service
  848. (documentation "Nar Herder")
  849. (provision '(nar-herder))
  850. (requirement '(networking))
  851. (start #~(make-forkexec-constructor
  852. (list #$(file-append package
  853. "/bin/nar-herder")
  854. "run-server"
  855. "--pid-file=/var/run/nar-herder/pid"
  856. #$(string-append "--port=" (number->string port))
  857. #$(string-append "--host=" host)
  858. #$@(if mirror
  859. (list (string-append "--mirror=" mirror))
  860. '())
  861. #$(string-append "--database=" database)
  862. #$(string-append "--database-dump=" database-dump)
  863. #$@(if storage
  864. (list (string-append "--storage=" storage))
  865. '())
  866. #$(string-append "--storage-limit="
  867. (if (number? storage-limit)
  868. (number->string storage-limit)
  869. storage-limit))
  870. #$@(map (lambda (criteria)
  871. (string-append
  872. "--storage-nar-removal-criteria="
  873. (match criteria
  874. ((k . v) (simple-format #f "~A=~A" k v))
  875. (str str))))
  876. storage-nar-removal-criteria)
  877. #$@(if ttl
  878. (list (string-append "--ttl=" ttl))
  879. '())
  880. #$@(if negative-ttl
  881. (list (string-append "--negative-ttl=" negative-ttl))
  882. '())
  883. #$@(if log-level
  884. (list (simple-format #f "--log-level=~A" log-level))
  885. '())
  886. #$@(append-map
  887. cached-compression-configuration->options
  888. cached-compressions)
  889. #$@(if cached-compression-min-uses
  890. (list (simple-format
  891. #f "--cached-compression-min-uses=~A"
  892. cached-compression-min-uses))
  893. '())
  894. #$@(if cached-compression-workers
  895. (list (simple-format
  896. #f "--cached-compression-workers=~A"
  897. cached-compression-workers))
  898. '())
  899. #$@(if cached-compression-nar-source
  900. (list (simple-format
  901. #f "--cached-compression-nar-source=~A"
  902. cached-compression-nar-source))
  903. '()))
  904. #:user #$user
  905. #:group #$group
  906. #:pid-file "/var/run/nar-herder/pid"
  907. #:environment-variables
  908. `(,(string-append
  909. "GUIX_LOCPATH=" #$glibc-utf8-locales "/lib/locale")
  910. "LC_ALL=en_US.utf8"
  911. #$@extra-environment-variables)
  912. #:log-file "/var/log/nar-herder/server.log"))
  913. (stop #~(make-kill-destructor))))))
  914. (define (nar-herder-activation config)
  915. #~(begin
  916. (use-modules (guix build utils))
  917. (define %user
  918. (getpw #$(nar-herder-configuration-user
  919. config)))
  920. (chmod "/var/lib/nar-herder" #o755)
  921. (mkdir-p "/var/log/nar-herder")
  922. ;; Allow writing the PID file
  923. (mkdir-p "/var/run/nar-herder")
  924. (chown "/var/run/nar-herder"
  925. (passwd:uid %user)
  926. (passwd:gid %user))))
  927. (define (nar-herder-account config)
  928. (match-record config <nar-herder-configuration>
  929. (user group)
  930. (list (user-group
  931. (name group)
  932. (system? #t))
  933. (user-account
  934. (name user)
  935. (group group)
  936. (system? #t)
  937. (comment "Nar Herder user")
  938. (home-directory "/var/lib/nar-herder")
  939. (shell (file-append shadow "/sbin/nologin"))))))
  940. (define nar-herder-service-type
  941. (service-type
  942. (name 'nar-herder)
  943. (extensions
  944. (list
  945. (service-extension shepherd-root-service-type
  946. nar-herder-shepherd-services)
  947. (service-extension activation-service-type
  948. nar-herder-activation)
  949. (service-extension account-service-type
  950. nar-herder-account)))
  951. (description
  952. "Run a Nar Herder server.")))