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