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