projects/guix·blob perlssl · refs

860 lines · 34.4 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2016 Nikita <[email protected]>
3;;; Copyright © 2016 Sou Bunnbu <[email protected]>
4;;; Copyright © 2017 Oleg Pykhalov <[email protected]>
5;;; Copyright © 2017 Clément Lassieur <[email protected]>
6;;; Copyright © 2018 Christopher Baines <[email protected]>
7;;; Copyright © 2021 Julien Lepiller <[email protected]>
8;;; Copyright © 2025 Tomas Volf <[email protected]>
9;;; Copyright © 2025 Evgeny Pisemsky <[email protected]>
10;;; Copyright © 2026 Nguyễn Gia Phong <[email protected]>
11;;;
12;;; This file is part of GNU Guix.
13;;;
14;;; GNU Guix is free software; you can redistribute it and/or modify it
15;;; under the terms of the GNU General Public License as published by
16;;; the Free Software Foundation; either version 3 of the License, or (at
17;;; your option) any later version.
18;;;
19;;; GNU Guix is distributed in the hope that it will be useful, but
20;;; WITHOUT ANY WARRANTY; without even the implied warranty of
21;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22;;; GNU General Public License for more details.
23;;;
24;;; You should have received a copy of the GNU General Public License
25;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26
27(define-module (gnu services version-control)
28 #:use-module (gnu services)
29 #:use-module (gnu services base)
30 #:use-module (gnu services configuration)
31 #:use-module (gnu services shepherd)
32 #:use-module (gnu services web)
33 #:use-module (gnu system shadow)
34 #:use-module (gnu packages version-control)
35 #:use-module (gnu packages admin)
36 #:use-module (guix deprecation)
37 #:use-module (guix packages)
38 #:use-module (guix records)
39 #:use-module (guix gexp)
40 #:use-module (guix store)
41 #:use-module (srfi srfi-1)
42 #:use-module (srfi srfi-26)
43 #:use-module (ice-9 format)
44 #:use-module (ice-9 match)
45 #:export (git-daemon-service
46 git-daemon-service-type
47 git-daemon-configuration
48 git-daemon-configuration?
49
50 git-http-configuration
51 git-http-configuration?
52 git-http-nginx-location-configuration
53
54 <gitolite-configuration>
55 gitolite-configuration
56 gitolite-configuration-package
57 gitolite-configuration-user
58 gitolite-configuration-rc-file
59 gitolite-configuration-admin-pubkey
60 gitolite-configuration-admin-name
61
62 <gitolite-rc-file>
63 gitolite-rc-file
64 gitolite-rc-file-local-code
65 gitolite-rc-file-umask
66 gitolite-rc-file-unsafe-pattern
67 gitolite-rc-file-git-config-keys
68 gitolite-rc-file-log-extra
69 gitolite-rc-file-host-name
70 gitolite-rc-file-roles
71 gitolite-rc-file-enable
72 gitolite-rc-file-extra-content
73 gitolite-rc-file-default-enable
74
75 <gitolite-git-configuration>
76 gitolite-git-configuration
77 gitolite-git-configuration?
78 gitolite-git-configuration-name
79 gitolite-git-configuration-email
80 gitolite-git-configuration-default-branch
81 gitolite-git-configuration-receive-fsck-objects
82 gitolite-git-configuration-extra-content
83
84 gitolite-service-type
85
86 gitile-configuration
87 gitile-configuration-package
88 gitile-configuration-host
89 gitile-configuration-port
90 gitile-configuration-database
91 gitile-configuration-repositories
92 gitile-configuration-git-owner-validation?
93 gitile-configuration-base-git-url
94 gitile-configuration-index-title
95 gitile-configuration-intro
96 gitile-configuration-footer
97 gitile-configuration-nginx
98
99 gitile-service-type
100
101 fossil-configuration
102 fossil-configuration-fields
103 fossil-configuration?
104 fossil-configuration-package
105 fossil-configuration-user
106 fossil-configuration-group
107 fossil-configuration-log-file
108 fossil-configuration-repository
109 fossil-configuration-acme?
110 fossil-configuration-base-url
111 fossil-configuration-chroot
112 fossil-configuration-ckout-alias
113 fossil-configuration-compress?
114 fossil-configuration-create?
115 fossil-configuration-error-log-file
116 fossil-configuration-ext-root
117 fossil-configuration-files
118 fossil-configuration-from
119 fossil-configuration-jail?
120 fossil-configuration-js-mode
121 fossil-configuration-https?
122 fossil-configuration-ip
123 fossil-configuration-local-authentication?
124 fossil-configuration-main-menu
125 fossil-configuration-max-latency
126 fossil-configuration-port
127 fossil-configuration-list-repositories?
128 fossil-configuration-redirect-to-https?
129 fossil-configuration-skin
130 fossil-configuration-socket-file
131 fossil-configuration-socket-mode
132 fossil-configuration-th-trace?
133 fossil-configuration-tls-certificate
134 fossil-configuration-tls-private-key
135
136 fossil-service-type))
137
138;;; Commentary:
139;;;
140;;; Version Control related services.
141;;;
142;;; Code:
143
144
145;;;
146;;; Git daemon.
147;;;
148
149(define-record-type* <git-daemon-configuration>
150 git-daemon-configuration
151 make-git-daemon-configuration
152 git-daemon-configuration?
153 (package git-daemon-configuration-package ;file-like
154 (default git))
155 (export-all? git-daemon-configuration-export-all ;boolean
156 (default #f))
157 (base-path git-daemon-configuration-base-path ;string | #f
158 (default "/srv/git"))
159 (user-path git-daemon-configuration-user-path ;string | #f
160 (default #f))
161 (listen git-daemon-configuration-listen ;list of string
162 (default '()))
163 (port git-daemon-configuration-port ;number | #f
164 (default #f))
165 (whitelist git-daemon-configuration-whitelist ;list of string
166 (default '()))
167 (extra-options git-daemon-configuration-extra-options ;list of string
168 (default '())))
169
170(define git-daemon-shepherd-service
171 (match-lambda
172 (($ <git-daemon-configuration>
173 package export-all? base-path user-path
174 listen port whitelist extra-options)
175 (let* ((git (file-append package "/bin/git"))
176 (command `(,git
177 "daemon" "--syslog" "--reuseaddr"
178 ,@(if export-all?
179 '("--export-all")
180 '())
181 ,@(if base-path
182 `(,(string-append "--base-path=" base-path))
183 '())
184 ,@(if user-path
185 `(,(string-append "--user-path=" user-path))
186 '())
187 ,@(map (cut string-append "--listen=" <>) listen)
188 ,@(if port
189 `(,(string-append
190 "--port=" (number->string port)))
191 '())
192 ,@extra-options
193 ,@whitelist)))
194 (list (shepherd-service
195 (documentation "Run the git-daemon.")
196 (requirement '(user-processes networking))
197 (provision '(git-daemon))
198 (start #~(make-forkexec-constructor '#$command
199 #:user "git-daemon"
200 #:group "git-daemon"))
201 (stop #~(make-kill-destructor))))))))
202
203(define %git-daemon-accounts
204 ;; User account and group for git-daemon.
205 (list (user-group
206 (name "git-daemon")
207 (system? #t))
208 (user-account
209 (name "git-daemon")
210 (system? #t)
211 (group "git-daemon")
212 (comment "Git daemon user")
213 (home-directory "/var/empty")
214 (shell (file-append shadow "/sbin/nologin")))))
215
216(define (git-daemon-activation config)
217 "Return the activation gexp for git-daemon using CONFIG."
218 (let ((base-path (git-daemon-configuration-base-path config)))
219 #~(begin
220 (use-modules (guix build utils))
221 ;; Create the 'base-path' directory when it's not '#f'.
222 (and=> #$base-path mkdir-p))))
223
224(define git-daemon-service-type
225 (service-type
226 (name 'git-daemon)
227 (extensions
228 (list (service-extension shepherd-root-service-type
229 git-daemon-shepherd-service)
230 (service-extension account-service-type
231 (const %git-daemon-accounts))
232 (service-extension activation-service-type
233 git-daemon-activation)))
234 (description
235 "Expose Git repositories over the insecure @code{git://} TCP-based
236protocol.")
237 (default-value (git-daemon-configuration))))
238
239(define-deprecated (git-daemon-service #:key (config (git-daemon-configuration)))
240 git-daemon-service-type
241 "Return a service that runs @command{git daemon}, a simple TCP server to
242expose repositories over the Git protocol for anonymous access.
243
244The optional @var{config} argument should be a
245@code{<git-daemon-configuration>} object, by default it allows read-only
246access to exported repositories under @file{/srv/git}."
247 (service git-daemon-service-type config))
248
249
250;;;
251;;; HTTP access. Add the result of calling
252;;; git-http-nginx-location-configuration to an nginx-server-configuration's
253;;; "locations" field.
254;;;
255
256(define-record-type* <git-http-configuration>
257 git-http-configuration
258 make-git-http-configuration
259 git-http-configuration?
260 (package git-http-configuration-package ;file-like
261 (default git))
262 (git-root git-http-configuration-git-root ;string
263 (default "/srv/git"))
264 (export-all? git-http-configuration-export-all? ;boolean
265 (default #f))
266 (uri-path git-http-configuration-uri-path ;string
267 (default "/git/"))
268 (fcgiwrap-socket git-http-configuration-fcgiwrap-socket ;string
269 (default "127.0.0.1:9000")))
270
271(define* (git-http-nginx-location-configuration #:optional
272 (config
273 (git-http-configuration)))
274 (match config
275 (($ <git-http-configuration> package git-root export-all?
276 uri-path fcgiwrap-socket)
277 (nginx-location-configuration
278 (uri (string-append "~ /" (string-trim-both uri-path #\/) "(/.*)"))
279 (body
280 (list
281 (list "fastcgi_pass " fcgiwrap-socket ";")
282 (list "fastcgi_param SCRIPT_FILENAME "
283 package "/libexec/git-core/git-http-backend"
284 ";")
285 "fastcgi_param QUERY_STRING $query_string;"
286 "fastcgi_param REQUEST_METHOD $request_method;"
287 "fastcgi_param CONTENT_TYPE $content_type;"
288 "fastcgi_param CONTENT_LENGTH $content_length;"
289 (if export-all?
290 "fastcgi_param GIT_HTTP_EXPORT_ALL \"\";"
291 "")
292 (list "fastcgi_param GIT_PROJECT_ROOT " git-root ";")
293 (list "fastcgi_param GIT_CONFIG_GLOBAL "
294 (plain-file "gitconfig"
295 (string-append "[safe]\n\tdirectory = " git-root "/*\n"))
296 ";")
297 "fastcgi_param PATH_INFO $1;"))))))
298
299
300;;;
301;;; Gitolite
302;;;
303
304(define gitolite-rc-file-default-enable
305 '("help"
306 "desc"
307 "info"
308 "perms"
309 "writable"
310 "ssh-authkeys"
311 "git-config"
312 "daemon"
313 "gitweb"))
314
315(define-record-type* <gitolite-rc-file>
316 gitolite-rc-file make-gitolite-rc-file
317 gitolite-rc-file?
318 (umask gitolite-rc-file-umask
319 (default #o0077))
320 (local-code gitolite-rc-file-local-code
321 (default "$rc{GL_ADMIN_BASE}/local"))
322 (unsafe-pattern gitolite-rc-file-unsafe-pattern
323 (default #f))
324 (git-config-keys gitolite-rc-file-git-config-keys
325 (default ""))
326 (log-extra gitolite-rc-file-log-extra
327 (default #f))
328 (host-name gitolite-rc-file-host-name
329 (default #f))
330 (roles gitolite-rc-file-roles
331 (default '(("READERS" . 1)
332 ("WRITERS" . 1))))
333 (enable gitolite-rc-file-enable
334 (default gitolite-rc-file-default-enable))
335 (extra-content gitolite-rc-extra-content
336 (default "")))
337
338(define-gexp-compiler (gitolite-rc-file-compiler
339 (file <gitolite-rc-file>) system target)
340 (match-record file <gitolite-rc-file>
341 ( umask local-code unsafe-pattern git-config-keys log-extra
342 host-name roles enable extra-content)
343 (apply text-file* "gitolite.rc"
344 `("%RC = (\n"
345 " UMASK => " ,(format #f "~4,'0o" umask) ",\n"
346 " GIT_CONFIG_KEYS => '" ,git-config-keys "',\n"
347 ,(if local-code
348 (simple-format #f " LOCAL_CODE => \"~A\",\n" local-code)
349 "")
350 ,(if log-extra
351 " LOG_EXTRA => 1,\n"
352 "")
353 ,(if host-name
354 (simple-format #f " HOSTNAME => \"~A\",\n" host-name)
355 "")
356 " ROLES => {\n"
357 ,@(map (match-lambda
358 ((role . value)
359 (simple-format #f " ~A => ~A,\n" role value)))
360 roles)
361 " },\n"
362 "\n"
363 " ENABLE => [\n"
364 ,@(map (lambda (value)
365 (simple-format #f " '~A',\n" value))
366 enable)
367 " ],\n"
368 ,extra-content "\n"
369 ");\n"
370 "\n"
371 ,(if unsafe-pattern
372 (string-append "$UNSAFE_PATT = qr(" unsafe-pattern ");")
373 "")
374 "1;\n"
375 "# Local variables:\n"
376 "# mode: perl\n"
377 "# End:\n"
378 "# vim: set syn=perl:\n"))))
379
380(define-record-type* <gitolite-git-configuration>
381 gitolite-git-configuration make-gitolite-git-configuration
382 gitolite-git-configuration?
383 (name gitolite-git-configuration-name
384 (default "GNU Guix"))
385 (email gitolite-git-configuration-email
386 (default "guix@localhost"))
387 (default-branch gitolite-git-configuration-default-branch
388 (default #f))
389 (receive-fsck-objects gitolite-git-configuration-receive-fsck-objects
390 (default #f))
391 (extra-content gitolite-git-configuration-extra-content
392 (default "")))
393
394(define-gexp-compiler (gitolite-git-configuration-compiler
395 (config <gitolite-git-configuration>) system target)
396 (match-record config <gitolite-git-configuration>
397 (name email default-branch receive-fsck-objects extra-content)
398 (apply text-file* "gitconfig"
399 `("[user]\n"
400 "name = " ,name "\n"
401 "email = " ,email "\n"
402 ,@(if default-branch
403 `("[init]\n"
404 "defaultBranch = " ,default-branch "\n")
405 '())
406 ,@(if receive-fsck-objects
407 `("[receive]\n"
408 "fsckObjects = true\n")
409 '())
410 ,extra-content "\n"))))
411
412(define-record-type* <gitolite-configuration>
413 gitolite-configuration make-gitolite-configuration
414 gitolite-configuration?
415 (package gitolite-configuration-package
416 (default gitolite))
417 (user gitolite-configuration-user
418 (default "git"))
419 (group gitolite-configuration-group
420 (default "git"))
421 (home-directory gitolite-configuration-home-directory
422 (default "/var/lib/gitolite"))
423 (rc-file gitolite-configuration-rc-file
424 (default (gitolite-rc-file)))
425 (git-config gitolite-configuration-git-config
426 (default (gitolite-git-configuration)))
427 (admin-pubkey gitolite-configuration-admin-pubkey)
428 (admin-name gitolite-configuration-admin-name
429 (default #f)))
430
431(define (gitolite-accounts config)
432 (match-record config <gitolite-configuration>
433 (user group home-directory)
434 ;; User group and account to run Gitolite.
435 (list (user-group
436 (name group)
437 (system? #t))
438 (user-account
439 (name user)
440 (group group)
441 (system? #t)
442 (comment "Gitolite user")
443 (home-directory home-directory)))))
444
445(define (gitolite-activation config)
446 (match-record config <gitolite-configuration>
447 ( package user group home-directory rc-file admin-pubkey
448 admin-name git-config)
449 #~(begin
450 (use-modules (ice-9 match)
451 (guix build utils))
452
453 (let* ((user-info (getpwnam #$user))
454 (admin-pubkey #$admin-pubkey)
455 (pubkey-file (if #$admin-name
456 (string-append #$admin-name ".pub")
457 (string-append
458 #$home-directory "/"
459 (basename
460 (strip-store-file-name admin-pubkey)))))
461 (rc-file #$(string-append home-directory "/.gitolite.rc")))
462
463 ;; activate-users+groups in (gnu build activation) sets the
464 ;; permission flags of home directories to #o700 and mentions that
465 ;; services needing looser permissions should chmod it during
466 ;; service activation. We also want the git group to be able to
467 ;; read from the gitolite home directory, so a chmod'ing we will
468 ;; go!
469 (chmod #$home-directory #o750)
470
471 (simple-format #t "guix: gitolite: installing ~A\n" #$rc-file)
472 (copy-file #$rc-file rc-file)
473 ;; ensure gitolite's user can read the configuration
474 (chown rc-file
475 (passwd:uid user-info)
476 (passwd:gid user-info))
477
478 ;; The key must be writable, so copy it from the store
479 (copy-file admin-pubkey pubkey-file)
480
481 (chmod pubkey-file #o500)
482 (chown pubkey-file
483 (passwd:uid user-info)
484 (passwd:gid user-info))
485
486 ;; Set the git configuration, to avoid gitolite trying to use
487 ;; the hostname command, as the network might not be up yet
488 (copy-file #$git-config
489 #$(string-append home-directory "/.gitconfig"))
490
491 ;; Run Gitolite setup, as this updates the hooks and include the
492 ;; admin pubkey if specified. The admin pubkey is required for
493 ;; initial setup, and will replace the previous key if run after
494 ;; initial setup
495 (match (primitive-fork)
496 (0
497 ;; Exit with a non-zero status code if an exception is thrown.
498 (dynamic-wind
499 (const #t)
500 (lambda ()
501 (setenv "HOME" (passwd:dir user-info))
502 (setenv "USER" #$user)
503 (setgid (passwd:gid user-info))
504 (setuid (passwd:uid user-info))
505 (primitive-exit
506 (system* #$(file-append package "/bin/gitolite")
507 "setup"
508 "-m" "gitolite setup by GNU Guix"
509 "-pk" pubkey-file)))
510 (lambda ()
511 (primitive-exit 1))))
512 (pid (waitpid pid)))
513
514 (when (file-exists? pubkey-file)
515 (delete-file pubkey-file))))))
516
517(define gitolite-service-type
518 (service-type
519 (name 'gitolite)
520 (extensions
521 (list (service-extension activation-service-type
522 gitolite-activation)
523 (service-extension account-service-type
524 gitolite-accounts)))
525 (description
526 "Set up @command{gitolite}, a Git hosting tool providing access over SSH.
527By default, the @code{git} user is used, but this is configurable.
528Additionally, Gitolite can integrate with with tools like gitweb or cgit to
529provide a web interface to view selected repositories.")))
530
531;;;
532;;; Gitile
533;;;
534
535(define-record-type* <gitile-configuration>
536 gitile-configuration make-gitile-configuration gitile-configuration?
537 (package gitile-configuration-package
538 (default gitile))
539 (host gitile-configuration-host
540 (default "127.0.0.1"))
541 (port gitile-configuration-port
542 (default 8080))
543 (database gitile-configuration-database
544 (default "/var/lib/gitile/gitile-db.sql"))
545 (repositories gitile-configuration-repositories
546 (default "/var/lib/gitolite/repositories"))
547 (git-owner-validation? gitile-configuration-git-owner-validation?
548 (default #t))
549 (base-git-url gitile-configuration-base-git-url)
550 (index-title gitile-configuration-index-title
551 (default "Index"))
552 (intro gitile-configuration-intro
553 (default '()))
554 (footer gitile-configuration-footer
555 (default '()))
556 (nginx gitile-configuration-nginx))
557
558(define (gitile-config-file host port database repositories
559 git-owner-validation? base-git-url
560 index-title intro footer)
561 (define build
562 #~(write `(config
563 (port #$port)
564 (host #$host)
565 (database #$database)
566 (repositories #$repositories)
567 (git-owner-validation? #$git-owner-validation?)
568 (base-git-url #$base-git-url)
569 (index-title #$index-title)
570 (intro #$intro)
571 (footer #$footer))
572 (open-output-file #$output)))
573
574 (computed-file "gitile.conf" build))
575
576(define gitile-nginx-server-block
577 (match-lambda
578 (($ <gitile-configuration> package host port database repositories
579 git-owner-validation? base-git-url index-title intro footer nginx)
580 (list (nginx-server-configuration
581 (inherit nginx)
582 (locations
583 (append
584 (list
585 (nginx-location-configuration
586 (uri "/")
587 (body
588 (list
589 #~(string-append "proxy_pass http://" #$host
590 ":" (number->string #$port)
591 "/;")))))
592 (map
593 (lambda (loc)
594 (nginx-location-configuration
595 (uri loc)
596 (body
597 (list
598 #~(string-append "root " #$package "/share/gitile/assets;")))))
599 '("/css" "/js" "/images"))
600 (nginx-server-configuration-locations nginx))))))))
601
602(define gitile-shepherd-service
603 (match-lambda
604 (($ <gitile-configuration> package host port database repositories
605 git-owner-validation? base-git-url index-title intro footer nginx)
606 (list (shepherd-service
607 (provision '(gitile))
608 (requirement '(loopback))
609 (documentation "gitile")
610 (start (let ((gitile (file-append package "/bin/gitile")))
611 #~(make-forkexec-constructor
612 `(,#$gitile "-c" #$(gitile-config-file
613 host port database
614 repositories
615 git-owner-validation?
616 base-git-url index-title
617 intro footer))
618 #:user "gitile"
619 #:group "git")))
620 (stop #~(make-kill-destructor)))))))
621
622(define %gitile-accounts
623 (list (user-group
624 (name "git")
625 (system? #t))
626 (user-account
627 (name "gitile")
628 (group "git")
629 (system? #t)
630 (comment "Gitile user")
631 (home-directory "/var/empty")
632 (shell (file-append shadow "/sbin/nologin")))))
633
634(define gitile-service-type
635 (service-type
636 (name 'gitile)
637 (description "Run Gitile, a small Git forge. Expose public repositories
638on the web.")
639 (extensions
640 (list (service-extension account-service-type
641 (const %gitile-accounts))
642 (service-extension shepherd-root-service-type
643 gitile-shepherd-service)
644 (service-extension nginx-service-type
645 gitile-nginx-server-block)))))
646
647
648;;;
649;;; Fossil HTTP server.
650;;;
651
652(define (port-number? n)
653 (and (integer? n)
654 (> n 0)
655 (< n (expt 2 16))))
656
657(define (mode-number? n)
658 (and (integer? n)
659 (>= n 0)
660 (<= n #o777)))
661
662(define (fossil-js-mode? x)
663 (and (memq x '(inline separate bundled))
664 #t))
665
666(define-maybe/no-serialization number)
667(define-maybe/no-serialization string)
668(define-maybe/no-serialization list-of-strings)
669(define-maybe/no-serialization fossil-js-mode)
670
671(define-configuration/no-serialization fossil-configuration
672 (package (package fossil)
673 "The Fossil package to use.")
674 (user (string "fossil")
675 "The user running the Fossil server.")
676 (group (string "fossil")
677 "The user group running the Fossil server.")
678 (log-file (string "/var/log/fossil.log")
679 "The path to the server's log.")
680 (repository (string "/var/lib/fossil")
681 "The name of the Fossil repository to be served, or a directory
682containing one or more repositories with names ending in @code{.fossil}.
683
684In the latter case, a prefix of the URL pathname is used
685to search the directory for an appropriate repository.
686Files not matching the pattern @code{*.fossil*}
687will be served as static content. Invoke @command{fossil server --help}
688for more information.")
689 (acme? (boolean #f)
690 "Deliver files from the @code{.well-known} subdirectory.")
691 (base-url maybe-string
692 "The URL used as the base (useful for reverse proxies)")
693 (chroot maybe-string
694 "The directory to use for chroot instead of @code{repository}.")
695 (ckout-alias maybe-string
696 "The @var{name} for @code{/doc/@var{name}/...}
697to be treated as @code{/doc/ckout/...}.")
698 (compress? (boolean #t) "Compress HTTP response.")
699 (create? (boolean #f)
700 "Create a new @code{repository} if it does not already exist.")
701 (error-log-file maybe-string "The path for HTTP error log.")
702 (ext-root maybe-string "The document root for the /ext extension mechanism.")
703 (files maybe-list-of-strings "The glob patterns for static files.")
704 (from maybe-string
705 "The path to be used as the diff baseline for the /ckout page.")
706 (jail? (boolean #t)
707 "Whether to enter the chroot jail after dropping root privileges.")
708 (js-mode maybe-fossil-js-mode
709 "How JavaScript is delivered with pages, either @code{'inline}
710at the end of the HTML file, as @code{'separate} HTTP requests,
711or one single HTTP request for all JavaScript @code{'bundled} together.
712
713Depending on the needs of any given page, @code{'inline}
714and @code{'bundled} modes might result in a single amalgamated script
715or several, but both approaches result in fewer HTTP requests
716than the @code{'separate} mode.")
717 (https? (boolean #f)
718 "Indicate that the requests are coming through a reverse proxy
719that has already translated HTTPS into HTTP.")
720 (ip maybe-string "The IP for the server to listen on.")
721 (local-authentication? (boolean #f)
722 "Enable automatic login for requests from localhost.")
723 (localhost? (boolean #f) "Listen on @code{127.0.0.1} only.")
724 (main-menu maybe-string ;TODO: structure
725 "The file whose contents is to override
726the repository's @code{mainmenu} setting.")
727 (max-latency maybe-number
728 "The maximum latency in seconds for a single HTTP request.")
729 (port (port-number 8080) "The port number for the server to listen on.")
730 (list-repositories? (boolean #f)
731 "If @code{repository} is dir, URL @code{/} lists repos.")
732 (redirect-to-https? (boolean #t)
733 "If set to @code{#f}, do not force redirects to HTTPS
734regardless of the repository setting @code{redirect-to-https}.")
735 (scgi? (boolean #f) "Accept SCGI rather than HTTP.")
736 (skin maybe-string "The skin label to use, overriding repository settings.")
737 (socket-file maybe-string
738 "The unix-domain socket to use instead of TCP/IP.")
739 (socket-mode (mode-number #o640)
740 "The file permissions to set for the unix socket.")
741 (th-trace? (boolean #f)
742 "Trace TH1 execution (for debugging purposes).")
743 (tls-certificate maybe-string
744 "The certicate file (@file{fullchain.pem})
745with which to enable TLS (HTTPS) encryption.")
746 (tls-private-key maybe-string "The file storing the TLS private key."))
747
748(define (fossil-accounts config)
749 (match-record config <fossil-configuration> (user group)
750 (list (user-group (name group)
751 (system? #t))
752 (user-account (name user)
753 (group group)
754 (system? #t)
755 (comment "Fossil server user")
756 (home-directory "/var/empty")
757 (shell (file-append shadow "/sbin/nologin"))))))
758
759(define (fossil-activation config)
760 (match-record config <fossil-configuration> (user create? repository)
761 (with-imported-modules '((guix build utils))
762 #~(begin
763 (use-modules (guix build utils))
764 (let* ((pw (getpwnam #$user))
765 (uid (passwd:uid pw))
766 (gid (passwd:gid pw)))
767 (unless #$create? (chown #$repository uid gid)))))))
768
769(define (fossil-shepherd-service config)
770 (match-record config <fossil-configuration>
771 (package user group log-file repository acme? base-url
772 chroot ckout-alias compress? create? error-log-file ext-root
773 files from https? ip jail? js-mode list-repositories?
774 local-authentication? localhost? main-menu max-latency port
775 redirect-to-https? scgi? skin socket-file socket-mode
776 th-trace? tls-certificate tls-private-key)
777 (shepherd-service
778 (provision '(fossil))
779 (requirement '(user-processes networking))
780 (start #~(make-forkexec-constructor
781 (list #$(file-append package "/bin/fossil")
782 "server"
783 #$@(if acme? '("--acme") '())
784 #$@(if (maybe-value-set? base-url)
785 (list "--baseurl" base-url)
786 '())
787 #$@(if (maybe-value-set? chroot)
788 (list "--chroot" chroot)
789 '())
790 #$@(if (maybe-value-set? ckout-alias)
791 (list "--ckout-alias" ckout-alias)
792 '())
793 #$@(if compress? '() '("--nocompress"))
794 #$@(if create? '("--create") '())
795 #$@(if (maybe-value-set? error-log-file)
796 (list "--errorlog" error-log-file)
797 '())
798 #$@(if (maybe-value-set? ext-root)
799 (list "--extroot" ext-root)
800 '())
801 #$@(if (maybe-value-set? files)
802 (list "--files" (string-join files ","))
803 '())
804 #$@(if (maybe-value-set? from) (list "--from" from) '())
805 #$@(if https? '("--https") '())
806 #$@(if jail? '() '("--nojail"))
807 #$@(if (maybe-value-set? js-mode)
808 (list "--jsmode" (symbol->string js-mode))
809 '())
810 #$@(if local-authentication? '("--localauth") '())
811 #$@(if localhost? '("--localhost") '())
812 #$@(if (maybe-value-set? main-menu)
813 (list "--mainmenu" main-menu)
814 '())
815 #$@(if (maybe-value-set? max-latency)
816 (list "--max-latency"
817 (number->string max-latency))
818 '())
819 #$@(if redirect-to-https? '() '("--nossl"))
820 #$@(if scgi? '("--scgi") '())
821 #$@(if list-repositories? '("--repolist") '())
822 #$@(if (maybe-value-set? skin) (list "--skin" skin) '())
823 #$@(if (maybe-value-set? socket-file)
824 (list "--socket-name" socket-file
825 "--socket-mode" socket-mode
826 "--socket-owner"
827 (simple-format #f "~a:~a" user group))
828 (list "--port"
829 (if (maybe-value-set? ip)
830 (simple-format #f "~a:~a" ip port)
831 (number->string port))))
832 #$@(if th-trace? '("--th-trace") '())
833 #$@(if (maybe-value-set? tls-certificate)
834 (list "--cert" tls-certificate)
835 '())
836 #$@(if (maybe-value-set? tls-private-key)
837 (list "--pkey" tls-private-key)
838 '())
839 "--user" #$user
840 #$repository)
841 #:user #$user
842 #:group #$group
843 #:log-file #$log-file))
844 (stop #~(make-kill-destructor))
845 (documentation
846 "Run the HTTP server
847for the Fossil software configuration management system."))))
848
849(define fossil-service-type
850 (service-type
851 (name 'fossil)
852 (extensions
853 (list (service-extension account-service-type fossil-accounts)
854 (service-extension activation-service-type fossil-activation)
855 (service-extension shepherd-root-service-type
856 (compose list fossil-shepherd-service))))
857 (description
858 "Run the HTTP server for the Fossil software configuration management
859system. In addition to distributed version control, Fossil also supports
860bug tracking, wiki, forum, email alerts, chat, and technotes.")))