guix.scm 48 KB

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