cgit.scm 25 KB

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