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