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