cgit.scm 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
  3. ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
  4. ;;; Copyright © 2018 Christopher Baines <mail@cbaines.net>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (gnu services cgit)
  21. #:use-module (gnu packages admin)
  22. #:use-module (gnu packages version-control)
  23. #:use-module (gnu services base)
  24. #:use-module (gnu services configuration)
  25. #:use-module (gnu services shepherd)
  26. #:use-module (gnu services web)
  27. #:use-module (gnu services)
  28. #:use-module (gnu system shadow)
  29. #:use-module (guix gexp)
  30. #:use-module (guix packages)
  31. #:use-module (guix records)
  32. #:use-module (guix store)
  33. #:use-module (ice-9 match)
  34. #:use-module (srfi srfi-1)
  35. #:use-module (srfi srfi-26)
  36. #:export (repository-cgit-configuration
  37. cgit-configuration
  38. %cgit-configuration-nginx
  39. cgit-configuration-nginx-config
  40. opaque-cgit-configuration
  41. cgit-service-type))
  42. ;;; Commentary:
  43. ;;;
  44. ;;; This module provides a service definition for the Cgit a web frontend for
  45. ;;; Git repositories written in C.
  46. ;;;
  47. ;;; Note: fields of <cgit-configuration> and <repository-cgit-configuration>
  48. ;;; should be specified in the specific order.
  49. ;;;
  50. ;;; Code:
  51. (define %cgit-configuration-nginx
  52. (nginx-server-configuration
  53. (root cgit)
  54. (locations
  55. (list
  56. (nginx-location-configuration
  57. (uri "@cgit")
  58. (body '("fastcgi_param SCRIPT_FILENAME $document_root/lib/cgit/cgit.cgi;"
  59. "fastcgi_param PATH_INFO $uri;"
  60. "fastcgi_param QUERY_STRING $args;"
  61. "fastcgi_param HTTP_HOST $server_name;"
  62. "fastcgi_pass 127.0.0.1:9000;")))))
  63. (try-files (list "$uri" "@cgit"))
  64. (listen '("80"))
  65. (ssl-certificate #f)
  66. (ssl-certificate-key #f)))
  67. ;;;
  68. ;;; Serialize <cgit-configuration>
  69. ;;;
  70. (define (uglify-field-name field-name)
  71. (string-delete #\? (symbol->string field-name)))
  72. (define (serialize-field field-name val)
  73. #~(format #f "~a=~a\n" #$(uglify-field-name field-name) #$val))
  74. (define (serialize-string field-name val)
  75. (if (and (string? val) (string=? val ""))
  76. ""
  77. (serialize-field field-name val)))
  78. (define (serialize-list field-name val)
  79. (if (null? val) "" (serialize-field field-name (string-join val))))
  80. (define robots-list? list?)
  81. (define (serialize-robots-list field-name val)
  82. (if (null? val) "" (serialize-field field-name (string-join val ", "))))
  83. (define (integer? val)
  84. (exact-integer? val))
  85. (define (serialize-integer field-name val)
  86. (serialize-field field-name (number->string val)))
  87. (define (serialize-boolean field-name val)
  88. (serialize-integer field-name (if val 1 0)))
  89. (define (serialize-repository-cgit-configuration x)
  90. (serialize-configuration x repository-cgit-configuration-fields))
  91. (define (repository-cgit-configuration-list? val)
  92. (list? val))
  93. (define (serialize-repository-cgit-configuration-list field-name val)
  94. #~(string-append
  95. #$@(map serialize-repository-cgit-configuration val)))
  96. (define (file-object? val)
  97. (or (file-like? val) (string? val)))
  98. (define (serialize-file-object field-name val)
  99. (serialize-string field-name val))
  100. (define (project-list? val)
  101. (or (list? val)
  102. (file-object? val)))
  103. ;;;
  104. ;;; Serialize <nginx-server-configuration>
  105. ;;;
  106. (define (nginx-server-configuration-list? val)
  107. (and (list? val) (and-map nginx-server-configuration? val)))
  108. (define (serialize-nginx-server-configuration-list field-name val)
  109. "")
  110. ;;;
  111. ;;; Serialize <repository-cgit-configuration>
  112. ;;;
  113. (define (serialize-repo-field field-name val)
  114. #~(format #f "repo.~a=~a\n" #$(uglify-field-name field-name) #$val))
  115. (define (serialize-repo-list field-name val)
  116. (if (null? val) "" (serialize-repo-field field-name (string-join val))))
  117. (define repo-boolean? boolean?)
  118. (define (serialize-repo-integer field-name val)
  119. (serialize-repo-field field-name (number->string val)))
  120. (define (serialize-repo-boolean field-name val)
  121. (serialize-repo-integer field-name (if val 1 0)))
  122. (define-maybe repo-boolean)
  123. (define repo-list? list?)
  124. (define repo-string? string?)
  125. (define (serialize-repo-string field-name val)
  126. (if (string=? val "") "" (serialize-repo-field field-name val)))
  127. (define repo-file-object? file-object?)
  128. (define serialize-repo-file-object serialize-repo-string)
  129. (define module-link-path? list?)
  130. (define (serialize-module-link-path field-name val)
  131. (if (null? val) ""
  132. (match val
  133. ((path text)
  134. (format #f "repo.module-link.~a=~a\n" path text)))))
  135. (define (serialize-project-list _ val)
  136. (if (null? val) ""
  137. (serialize-field
  138. 'project-list
  139. (if (file-object? val)
  140. val
  141. (plain-file "project-list" (string-join val "\n"))))))
  142. (define (serialize-extra-options extra-options)
  143. (string-join extra-options "\n" 'suffix))
  144. (define repository-directory? string?)
  145. (define (serialize-repository-directory _ val)
  146. (if (string=? val "") "" (format #f "scan-path=~a\n" val)))
  147. (define mimetype-alist? list?)
  148. (define (serialize-mimetype-alist field-name val)
  149. (format #f "# Mimetypes\n~a"
  150. (string-join
  151. (map (match-lambda
  152. ((extension mimetype)
  153. (format #f "mimetype.~a=~a"
  154. (symbol->string extension) mimetype)))
  155. val) "\n")))
  156. (define-configuration repository-cgit-configuration
  157. (snapshots
  158. (repo-list '())
  159. "A mask of snapshot formats for this repo that cgit generates links for,
  160. restricted by the global @code{snapshots} setting.")
  161. (source-filter
  162. (repo-file-object "")
  163. "Override the default @code{source-filter}.")
  164. (url
  165. (repo-string "")
  166. "The relative URL used to access the repository.")
  167. (about-filter
  168. (repo-file-object "")
  169. "Override the default @code{about-filter}.")
  170. (branch-sort
  171. (repo-string "")
  172. "Flag which, when set to @samp{age}, enables date ordering in the branch
  173. ref list, and when set to @samp{name} enables ordering by branch name.")
  174. (clone-url
  175. (repo-list '())
  176. "A list of URLs which can be used to clone repo.")
  177. (commit-filter
  178. (repo-file-object "")
  179. "Override the default @code{commit-filter}.")
  180. (commit-sort
  181. (repo-string "")
  182. "Flag which, when set to @samp{date}, enables strict date ordering in the
  183. commit log, and when set to @samp{topo} enables strict topological ordering.")
  184. (defbranch
  185. (repo-string "")
  186. "The name of the default branch for this repository. If no such branch
  187. exists in the repository, the first branch name (when sorted) is used as
  188. default instead. By default branch pointed to by HEAD, or \"master\" if there
  189. is no suitable HEAD.")
  190. (desc
  191. (repo-string "")
  192. "The value to show as repository description.")
  193. (homepage
  194. (repo-string "")
  195. "The value to show as repository homepage.")
  196. (email-filter
  197. (repo-file-object "")
  198. "Override the default @code{email-filter}.")
  199. (enable-commit-graph?
  200. (maybe-repo-boolean 'disabled)
  201. "A flag which can be used to disable the global setting
  202. @code{enable-commit-graph?}.")
  203. (enable-log-filecount?
  204. (maybe-repo-boolean 'disabled)
  205. "A flag which can be used to disable the global setting
  206. @code{enable-log-filecount?}.")
  207. (enable-log-linecount?
  208. (maybe-repo-boolean 'disabled)
  209. "A flag which can be used to disable the global setting
  210. @code{enable-log-linecount?}.")
  211. (enable-remote-branches?
  212. (maybe-repo-boolean 'disabled)
  213. "Flag which, when set to @code{#t}, will make cgit display remote
  214. branches in the summary and refs views.")
  215. (enable-subject-links?
  216. (maybe-repo-boolean 'disabled)
  217. "A flag which can be used to override the global setting
  218. @code{enable-subject-links?}.")
  219. (enable-html-serving?
  220. (maybe-repo-boolean 'disabled)
  221. "A flag which can be used to override the global setting
  222. @code{enable-html-serving?}.")
  223. (hide?
  224. (repo-boolean #f)
  225. "Flag which, when set to @code{#t}, hides the repository from the
  226. repository index.")
  227. (ignore?
  228. (repo-boolean #f)
  229. "Flag which, when set to @samp{#t}, ignores the repository.")
  230. (logo
  231. (repo-file-object "")
  232. "URL which specifies the source of an image which will be used as a
  233. logo on this repo’s pages.")
  234. (logo-link
  235. (repo-string "")
  236. "URL loaded when clicking on the cgit logo image.")
  237. (owner-filter
  238. (repo-file-object "")
  239. "Override the default @code{owner-filter}.")
  240. (module-link
  241. (repo-string "")
  242. "Text which will be used as the formatstring for a hyperlink when a
  243. submodule is printed in a directory listing. The arguments for the
  244. formatstring are the path and SHA1 of the submodule commit.")
  245. (module-link-path
  246. (module-link-path '())
  247. "Text which will be used as the formatstring for a hyperlink when a
  248. submodule with the specified subdirectory path is printed in a directory
  249. listing.")
  250. (max-stats
  251. (repo-string "")
  252. "Override the default maximum statistics period.")
  253. (name
  254. (repo-string "")
  255. "The value to show as repository name.")
  256. (owner
  257. (repo-string "")
  258. "A value used to identify the owner of the repository.")
  259. (path
  260. (repo-string "")
  261. "An absolute path to the repository directory.")
  262. (readme
  263. (repo-string "")
  264. "A path (relative to repo) which specifies a file to include verbatim
  265. as the \"About\" page for this repo.")
  266. (section
  267. (repo-string "")
  268. "The name of the current repository section - all repositories defined
  269. after this option will inherit the current section name.")
  270. (extra-options
  271. (repo-list '())
  272. "Extra options will be appended to cgitrc file."))
  273. ;; Generate a <cgit-configuration> record, which may include a list of
  274. ;; <repository-cgit-configuration>, <nginx-server-configuration>, <package>.
  275. (define-configuration cgit-configuration
  276. (package
  277. (package cgit)
  278. "The CGIT package.")
  279. (nginx
  280. (nginx-server-configuration-list (list %cgit-configuration-nginx))
  281. "NGINX configuration.")
  282. (about-filter
  283. (file-object "")
  284. "Specifies a command which will be invoked to format the content of about
  285. pages (both top-level and for each repository).")
  286. (agefile
  287. (string "")
  288. "Specifies a path, relative to each repository path, which can be used to
  289. specify the date and time of the youngest commit in the repository.")
  290. (auth-filter
  291. (file-object "")
  292. "Specifies a command that will be invoked for authenticating repository
  293. access.")
  294. (branch-sort
  295. (string "name")
  296. "Flag which, when set to @samp{age}, enables date ordering in the branch
  297. ref list, and when set @samp{name} enables ordering by branch name.")
  298. (cache-root
  299. (string "/var/cache/cgit")
  300. "Path used to store the cgit cache entries.")
  301. (cache-static-ttl
  302. (integer -1)
  303. "Number which specifies the time-to-live, in minutes, for the cached
  304. version of repository pages accessed with a fixed SHA1.")
  305. (cache-dynamic-ttl
  306. (integer 5)
  307. "Number which specifies the time-to-live, in minutes, for the cached
  308. version of repository pages accessed without a fixed SHA1.")
  309. (cache-repo-ttl
  310. (integer 5)
  311. "Number which specifies the time-to-live, in minutes, for the cached
  312. version of the repository summary page.")
  313. (cache-root-ttl
  314. (integer 5)
  315. "Number which specifies the time-to-live, in minutes, for the cached
  316. version of the repository index page.")
  317. (cache-scanrc-ttl
  318. (integer 15)
  319. "Number which specifies the time-to-live, in minutes, for the result of
  320. scanning a path for Git repositories.")
  321. (cache-about-ttl
  322. (integer 15)
  323. "Number which specifies the time-to-live, in minutes, for the cached
  324. version of the repository about page.")
  325. (cache-snapshot-ttl
  326. (integer 5)
  327. "Number which specifies the time-to-live, in minutes, for the cached
  328. version of snapshots.")
  329. (cache-size
  330. (integer 0)
  331. "The maximum number of entries in the cgit cache. When set to
  332. @samp{0}, caching is disabled.")
  333. (case-sensitive-sort?
  334. (boolean #t)
  335. "Sort items in the repo list case sensitively.")
  336. (clone-prefix
  337. (list '())
  338. "List of common prefixes which, when combined with a repository URL,
  339. generates valid clone URLs for the repository.")
  340. (clone-url
  341. (list '())
  342. "List of @code{clone-url} templates.")
  343. (commit-filter
  344. (file-object "")
  345. "Command which will be invoked to format commit messages.")
  346. (commit-sort
  347. (string "git log")
  348. "Flag which, when set to @samp{date}, enables strict date ordering in the
  349. commit log, and when set to @samp{topo} enables strict topological
  350. ordering.")
  351. (css
  352. (file-object "/share/cgit/cgit.css")
  353. "URL which specifies the css document to include in all cgit pages.")
  354. (email-filter
  355. (file-object "")
  356. "Specifies a command which will be invoked to format names and email
  357. address of committers, authors, and taggers, as represented in various
  358. places throughout the cgit interface.")
  359. (embedded?
  360. (boolean #f)
  361. "Flag which, when set to @samp{#t}, will make cgit generate a HTML
  362. fragment suitable for embedding in other HTML pages.")
  363. (enable-commit-graph?
  364. (boolean #f)
  365. "Flag which, when set to @samp{#t}, will make cgit print an ASCII-art
  366. commit history graph to the left of the commit messages in the
  367. repository log page.")
  368. (enable-filter-overrides?
  369. (boolean #f)
  370. "Flag which, when set to @samp{#t}, allows all filter settings to be
  371. overridden in repository-specific cgitrc files.")
  372. (enable-follow-links?
  373. (boolean #f)
  374. "Flag which, when set to @samp{#t}, allows users to follow a file in the
  375. log view.")
  376. (enable-http-clone?
  377. (boolean #t)
  378. "If set to @samp{#t}, cgit will act as an dumb HTTP endpoint for Git
  379. clones.")
  380. (enable-index-links?
  381. (boolean #f)
  382. "Flag which, when set to @samp{#t}, will make cgit generate extra links
  383. \"summary\", \"commit\", \"tree\" for each repo in the repository index.")
  384. (enable-index-owner?
  385. (boolean #t)
  386. "Flag which, when set to @samp{#t}, will make cgit display the owner of
  387. each repo in the repository index.")
  388. (enable-log-filecount?
  389. (boolean #f)
  390. "Flag which, when set to @samp{#t}, will make cgit print the number of
  391. modified files for each commit on the repository log page.")
  392. (enable-log-linecount?
  393. (boolean #f)
  394. "Flag which, when set to @samp{#t}, will make cgit print the number of
  395. added and removed lines for each commit on the repository log page.")
  396. (enable-remote-branches?
  397. (boolean #f)
  398. "Flag which, when set to @code{#t}, will make cgit display remote
  399. branches in the summary and refs views.")
  400. (enable-subject-links?
  401. (boolean #f)
  402. "Flag which, when set to @code{1}, will make cgit use the subject of
  403. the parent commit as link text when generating links to parent commits
  404. in commit view.")
  405. (enable-html-serving?
  406. (boolean #f)
  407. "Flag which, when set to @samp{#t}, will make cgit use the subject of the
  408. parent commit as link text when generating links to parent commits in
  409. commit view.")
  410. (enable-tree-linenumbers?
  411. (boolean #t)
  412. "Flag which, when set to @samp{#t}, will make cgit generate linenumber
  413. links for plaintext blobs printed in the tree view.")
  414. (enable-git-config?
  415. (boolean #f)
  416. "Flag which, when set to @samp{#f}, will allow cgit to use Git config to
  417. set any repo specific settings.")
  418. (favicon
  419. (file-object "/favicon.ico")
  420. "URL used as link to a shortcut icon for cgit.")
  421. (footer
  422. (string "")
  423. "The content of the file specified with this option will be included
  424. verbatim at the bottom of all pages (i.e. it replaces the standard
  425. \"generated by...\" message).")
  426. (head-include
  427. (string "")
  428. "The content of the file specified with this option will be included
  429. verbatim in the HTML HEAD section on all pages.")
  430. (header
  431. (string "")
  432. "The content of the file specified with this option will be included
  433. verbatim at the top of all pages.")
  434. (include
  435. (file-object "")
  436. "Name of a configfile to include before the rest of the current config-
  437. file is parsed.")
  438. (index-header
  439. (string "")
  440. "The content of the file specified with this option will be included
  441. verbatim above the repository index.")
  442. (index-info
  443. (string "")
  444. "The content of the file specified with this option will be included
  445. verbatim below the heading on the repository index page.")
  446. (local-time?
  447. (boolean #f)
  448. "Flag which, if set to @samp{#t}, makes cgit print commit and tag times
  449. in the servers timezone.")
  450. (logo
  451. (file-object "/share/cgit/cgit.png")
  452. "URL which specifies the source of an image which will be used as a logo
  453. on all cgit pages.")
  454. (logo-link
  455. (string "")
  456. "URL loaded when clicking on the cgit logo image.")
  457. (owner-filter
  458. (file-object "")
  459. "Command which will be invoked to format the Owner column of the main
  460. page.")
  461. (max-atom-items
  462. (integer 10)
  463. "Number of items to display in atom feeds view.")
  464. (max-commit-count
  465. (integer 50)
  466. "Number of entries to list per page in \"log\" view.")
  467. (max-message-length
  468. (integer 80)
  469. "Number of commit message characters to display in \"log\" view.")
  470. (max-repo-count
  471. (integer 50)
  472. "Specifies the number of entries to list per page on the repository index
  473. page.")
  474. (max-repodesc-length
  475. (integer 80)
  476. "Specifies the maximum number of repo description characters to display
  477. on the repository index page.")
  478. (max-blob-size
  479. (integer 0)
  480. "Specifies the maximum size of a blob to display HTML for in KBytes.")
  481. (max-stats
  482. (string "")
  483. "Maximum statistics period. Valid values are @samp{week},@samp{month},
  484. @samp{quarter} and @samp{year}.")
  485. (mimetype
  486. (mimetype-alist '((gif "image/gif")
  487. (html "text/html")
  488. (jpg "image/jpeg")
  489. (jpeg "image/jpeg")
  490. (pdf "application/pdf")
  491. (png "image/png")
  492. (svg "image/svg+xml")))
  493. "Mimetype for the specified filename extension.")
  494. (mimetype-file
  495. (file-object "")
  496. "Specifies the file to use for automatic mimetype lookup.")
  497. (module-link
  498. (string "")
  499. "Text which will be used as the formatstring for a hyperlink when a
  500. submodule is printed in a directory listing.")
  501. (nocache?
  502. (boolean #f)
  503. "If set to the value @samp{#t} caching will be disabled.")
  504. (noplainemail?
  505. (boolean #f)
  506. "If set to @samp{#t} showing full author email addresses will be
  507. disabled.")
  508. (noheader?
  509. (boolean #f)
  510. "Flag which, when set to @samp{#t}, will make cgit omit the standard
  511. header on all pages.")
  512. (project-list
  513. (project-list '())
  514. "A list of subdirectories inside of @code{repository-directory}, relative
  515. to it, that should loaded as Git repositories. An empty list means that all
  516. subdirectories will be loaded.")
  517. (readme
  518. (file-object "")
  519. "Text which will be used as default value for @code{cgit-repo-readme}.")
  520. (remove-suffix?
  521. (boolean #f)
  522. "If set to @code{#t} and @code{repository-directory} is enabled, if any
  523. repositories are found with a suffix of @code{.git}, this suffix will be
  524. removed for the URL and name.")
  525. (renamelimit
  526. (integer -1)
  527. "Maximum number of files to consider when detecting renames.")
  528. (repository-sort
  529. (string "")
  530. "The way in which repositories in each section are sorted.")
  531. (robots
  532. (robots-list (list "noindex" "nofollow"))
  533. "Text used as content for the @code{robots} meta-tag.")
  534. (root-desc
  535. (string "a fast webinterface for the git dscm")
  536. "Text printed below the heading on the repository index page.")
  537. (root-readme
  538. (string "")
  539. "The content of the file specified with this option will be included
  540. verbatim below thef \"about\" link on the repository index page.")
  541. (root-title
  542. (string "")
  543. "Text printed as heading on the repository index page.")
  544. (scan-hidden-path
  545. (boolean #f)
  546. "If set to @samp{#t} and repository-directory is enabled,
  547. repository-directory will recurse into directories whose name starts with a
  548. period. Otherwise, repository-directory will stay away from such directories,
  549. considered as \"hidden\". Note that this does not apply to the \".git\"
  550. directory in non-bare repos.")
  551. (snapshots
  552. (list '())
  553. "Text which specifies the default set of snapshot formats that cgit
  554. generates links for.")
  555. (repository-directory
  556. (repository-directory "/srv/git")
  557. "Name of the directory to scan for repositories (represents
  558. @code{scan-path}).")
  559. (section
  560. (string "")
  561. "The name of the current repository section - all repositories defined
  562. after this option will inherit the current section name.")
  563. (section-sort
  564. (string "")
  565. "Flag which, when set to @samp{1}, will sort the sections on the repository
  566. listing by name.")
  567. (section-from-path
  568. (integer 0)
  569. "A number which, if defined prior to repository-directory, specifies how
  570. many path elements from each repo path to use as a default section name.")
  571. (side-by-side-diffs?
  572. (boolean #f)
  573. "If set to @samp{#t} shows side-by-side diffs instead of unidiffs per
  574. default.")
  575. (source-filter
  576. (file-object "")
  577. "Specifies a command which will be invoked to format plaintext blobs in the
  578. tree view.")
  579. (summary-branches
  580. (integer 10)
  581. "Specifies the number of branches to display in the repository \"summary\"
  582. view.")
  583. (summary-log
  584. (integer 10)
  585. "Specifies the number of log entries to display in the repository
  586. \"summary\" view.")
  587. (summary-tags
  588. (integer 10)
  589. "Specifies the number of tags to display in the repository \"summary\"
  590. view.")
  591. (strict-export
  592. (string "")
  593. "Filename which, if specified, needs to be present within the repository
  594. for cgit to allow access to that repository.")
  595. (virtual-root
  596. (string "/")
  597. "URL which, if specified, will be used as root for all cgit links.")
  598. (repositories
  599. (repository-cgit-configuration-list '())
  600. "A list of @dfn{cgit-repo} records to use with config.")
  601. (extra-options
  602. (list '())
  603. "Extra options will be appended to cgitrc file."))
  604. ;; This distinguishes fields whose order matters, and makes sure further
  605. ;; changes won't inadvertently change the order.
  606. (define (serialize-cgit-configuration config)
  607. (define (rest? field)
  608. (not (memq (configuration-field-name field)
  609. '(project-list
  610. extra-options
  611. repository-directory
  612. repositories))))
  613. #~(string-append
  614. #$(let ((rest (filter rest? cgit-configuration-fields)))
  615. (serialize-configuration config rest))
  616. #$(serialize-project-list
  617. 'project-list
  618. (cgit-configuration-project-list config))
  619. #$(serialize-extra-options
  620. (cgit-configuration-extra-options config))
  621. #$(serialize-repository-directory
  622. 'repository-directory
  623. (cgit-configuration-repository-directory config))
  624. #$(serialize-repository-cgit-configuration-list
  625. 'repositories
  626. (cgit-configuration-repositories config))))
  627. (define-configuration opaque-cgit-configuration
  628. (cgit
  629. (package cgit)
  630. "The cgit package.")
  631. (cgitrc
  632. (string (configuration-missing-field 'opaque-cgit-configuration 'cgitrc))
  633. "The contents of the @code{cgitrc} to use.")
  634. (cache-root
  635. (string "/var/cache/cgit")
  636. "Path used to store the cgit cache entries.")
  637. (nginx
  638. (nginx-server-configuration-list (list %cgit-configuration-nginx))
  639. "NGINX configuration."))
  640. (define (cgit-activation config)
  641. "Return the activation gexp for CONFIG."
  642. (let* ((opaque-config? (opaque-cgit-configuration? config))
  643. (config-str
  644. (if opaque-config?
  645. (opaque-cgit-configuration-cgitrc config)
  646. (serialize-cgit-configuration config))))
  647. #~(begin
  648. (use-modules (guix build utils))
  649. (mkdir-p #$(if opaque-config?
  650. (opaque-cgit-configuration-cache-root config)
  651. (cgit-configuration-cache-root config)))
  652. (copy-file #$(mixed-text-file "cgitrc" config-str)
  653. "/etc/cgitrc"))))
  654. (define (cgit-configuration-nginx-config config)
  655. (if (opaque-cgit-configuration? config)
  656. (opaque-cgit-configuration-nginx config)
  657. (cgit-configuration-nginx config)))
  658. (define cgit-service-type
  659. (service-type
  660. (name 'cgit)
  661. (extensions
  662. (list (service-extension activation-service-type
  663. cgit-activation)
  664. (service-extension nginx-service-type
  665. cgit-configuration-nginx-config)
  666. ;; Make sure fcgiwrap is instantiated.
  667. (service-extension fcgiwrap-service-type
  668. (const #t))))
  669. (default-value (cgit-configuration))
  670. (description
  671. "Run the cgit web interface, which allows users to browse Git
  672. repositories.")))
  673. (define (generate-cgit-documentation)
  674. (generate-documentation
  675. `((cgit-configuration
  676. ,cgit-configuration-fields
  677. (repositories repository-cgit-configuration))
  678. (repository-cgit-configuration
  679. ,repository-cgit-configuration-fields))
  680. 'cgit-configuration))