Commit | Line | Data |
---|---|---|
a7cf4eb6 ML |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org> | |
8de938d5 | 3 | ;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org> |
11b7717d | 4 | ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com> |
a7cf4eb6 ML |
5 | ;;; |
6 | ;;; This file is part of GNU Guix. | |
7 | ;;; | |
8 | ;;; GNU Guix is free software: you can redistribute it and/or modify | |
9 | ;;; it under the terms of the GNU General Public License as published by | |
10 | ;;; the Free Software Foundation, either version 3 of the License, or | |
11 | ;;; (at your option) any later version. | |
12 | ;;; | |
13 | ;;; GNU Guix is distributed in the hope that it will be useful, | |
14 | ;;; but 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 cuirass) | |
22 | #:use-module (guix gexp) | |
23 | #:use-module (guix records) | |
24 | #:use-module (gnu packages admin) | |
25 | #:autoload (gnu packages ci) (cuirass) | |
75bddb13 | 26 | #:autoload (gnu packages version-control) (git) |
a7cf4eb6 ML |
27 | #:use-module (gnu services) |
28 | #:use-module (gnu services base) | |
29 | #:use-module (gnu services shepherd) | |
d782de17 | 30 | #:use-module (gnu services admin) |
a7cf4eb6 ML |
31 | #:use-module (gnu system shadow) |
32 | #:export (<cuirass-configuration> | |
33 | cuirass-configuration | |
34 | cuirass-configuration? | |
35 | ||
231eddc8 | 36 | cuirass-service-type)) |
a7cf4eb6 ML |
37 | |
38 | ;;;; Commentary: | |
39 | ;;; | |
40 | ;;; This module implements a service that to run instances of Cuirass, a | |
41 | ;;; continuous integration tool. | |
42 | ;;; | |
43 | ;;;; Code: | |
44 | ||
45 | (define-record-type* <cuirass-configuration> | |
46 | cuirass-configuration make-cuirass-configuration | |
47 | cuirass-configuration? | |
379b6ba5 LC |
48 | (cuirass cuirass-configuration-cuirass ;package |
49 | (default cuirass)) | |
b17e326f LC |
50 | (log-file cuirass-configuration-log-file ;string |
51 | (default "/var/log/cuirass.log")) | |
a7cf4eb6 | 52 | (cache-directory cuirass-configuration-cache-directory ;string (dir-name) |
463995da | 53 | (default "/var/cache/cuirass")) |
a7cf4eb6 ML |
54 | (user cuirass-configuration-user ;string |
55 | (default "cuirass")) | |
56 | (group cuirass-configuration-group ;string | |
57 | (default "cuirass")) | |
58 | (interval cuirass-configuration-interval ;integer (seconds) | |
59 | (default 60)) | |
60 | (database cuirass-configuration-database ;string (file-name) | |
61 | (default "/var/run/cuirass/cuirass.db")) | |
11b7717d | 62 | (port cuirass-configuration-port ;integer (port) |
1c05aab4 | 63 | (default 8081)) |
231eddc8 LC |
64 | (specifications cuirass-configuration-specifications) |
65 | ;gexp that evaluates to specification-alist | |
a7cf4eb6 ML |
66 | (use-substitutes? cuirass-configuration-use-substitutes? ;boolean |
67 | (default #f)) | |
68 | (one-shot? cuirass-configuration-one-shot? ;boolean | |
eb122280 | 69 | (default #f)) |
c800fd56 MO |
70 | (fallback? cuirass-configuration-fallback? ;boolean |
71 | (default #f)) | |
eb122280 MO |
72 | (load-path cuirass-configuration-load-path |
73 | (default '()))) | |
a7cf4eb6 ML |
74 | |
75 | (define (cuirass-shepherd-service config) | |
76 | "Return a <shepherd-service> for the Cuirass service with CONFIG." | |
77 | (and | |
78 | (cuirass-configuration? config) | |
379b6ba5 LC |
79 | (let ((cuirass (cuirass-configuration-cuirass config)) |
80 | (cache-directory (cuirass-configuration-cache-directory config)) | |
b17e326f | 81 | (log-file (cuirass-configuration-log-file config)) |
831071b8 LC |
82 | (user (cuirass-configuration-user config)) |
83 | (group (cuirass-configuration-group config)) | |
a7cf4eb6 ML |
84 | (interval (cuirass-configuration-interval config)) |
85 | (database (cuirass-configuration-database config)) | |
11b7717d | 86 | (port (cuirass-configuration-port config)) |
57aa94bd | 87 | (specs (cuirass-configuration-specifications config)) |
a7cf4eb6 | 88 | (use-substitutes? (cuirass-configuration-use-substitutes? config)) |
eb122280 | 89 | (one-shot? (cuirass-configuration-one-shot? config)) |
c800fd56 | 90 | (fallback? (cuirass-configuration-fallback? config)) |
eb122280 | 91 | (load-path (cuirass-configuration-load-path config))) |
a7cf4eb6 ML |
92 | (list (shepherd-service |
93 | (documentation "Run Cuirass.") | |
94 | (provision '(cuirass)) | |
f84011d0 | 95 | (requirement '(guix-daemon networking)) |
a7cf4eb6 ML |
96 | (start #~(make-forkexec-constructor |
97 | (list (string-append #$cuirass "/bin/cuirass") | |
463995da | 98 | "--cache-directory" #$cache-directory |
8de938d5 LC |
99 | "--specifications" |
100 | #$(scheme-file "cuirass-specs.scm" specs) | |
a7cf4eb6 | 101 | "--database" #$database |
11b7717d | 102 | "--port" #$(number->string port) |
a7cf4eb6 ML |
103 | "--interval" #$(number->string interval) |
104 | #$@(if use-substitutes? '("--use-substitutes") '()) | |
eb122280 | 105 | #$@(if one-shot? '("--one-shot") '()) |
c800fd56 | 106 | #$@(if fallback? '("--fallback") '()) |
eb122280 MO |
107 | #$@(if (null? load-path) '() |
108 | `("--load-path" ,(string-join load-path ":")))) | |
75bddb13 LC |
109 | |
110 | #:environment-variables | |
111 | (list "GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt" | |
112 | (string-append "GIT_EXEC_PATH=" #$git | |
113 | "/libexec/git-core")) | |
114 | ||
831071b8 LC |
115 | #:user #$user |
116 | #:group #$group | |
b17e326f | 117 | #:log-file #$log-file)) |
a7cf4eb6 ML |
118 | (stop #~(make-kill-destructor))))))) |
119 | ||
120 | (define (cuirass-account config) | |
121 | "Return the user accounts and user groups for CONFIG." | |
122 | (let ((cuirass-user (cuirass-configuration-user config)) | |
123 | (cuirass-group (cuirass-configuration-group config))) | |
124 | (list (user-group | |
125 | (name cuirass-group) | |
126 | (system? #t)) | |
127 | (user-account | |
128 | (name cuirass-user) | |
129 | (group cuirass-group) | |
130 | (system? #t) | |
131 | (comment "Cuirass privilege separation user") | |
132 | (home-directory (string-append "/var/run/" cuirass-user)) | |
133 | (shell #~(string-append #$shadow "/sbin/nologin")))))) | |
134 | ||
463995da LC |
135 | (define (cuirass-activation config) |
136 | "Return the activation code for CONFIG." | |
137 | (let ((cache (cuirass-configuration-cache-directory config)) | |
137f8df6 | 138 | (db (dirname (cuirass-configuration-database config))) |
463995da LC |
139 | (user (cuirass-configuration-user config)) |
140 | (group (cuirass-configuration-group config))) | |
141 | (with-imported-modules '((guix build utils)) | |
142 | #~(begin | |
143 | (use-modules (guix build utils)) | |
144 | ||
145 | (mkdir-p #$cache) | |
137f8df6 | 146 | (mkdir-p #$db) |
463995da LC |
147 | |
148 | (let ((uid (passwd:uid (getpw #$user))) | |
149 | (gid (group:gid (getgr #$group)))) | |
137f8df6 LC |
150 | (chown #$cache uid gid) |
151 | (chown #$db uid gid)))))) | |
463995da | 152 | |
d782de17 LC |
153 | (define (cuirass-log-rotations config) |
154 | "Return the list of log rotations that corresponds to CONFIG." | |
155 | (list (log-rotation | |
156 | (files (list (cuirass-configuration-log-file config))) | |
157 | (frequency 'weekly) | |
158 | (options '("rotate 40"))))) ;worth keeping | |
159 | ||
a7cf4eb6 ML |
160 | (define cuirass-service-type |
161 | (service-type | |
162 | (name 'cuirass) | |
163 | (extensions | |
164 | (list | |
38d6aa05 LC |
165 | (service-extension profile-service-type ;for 'info cuirass' |
166 | (compose list cuirass-configuration-cuirass)) | |
d782de17 | 167 | (service-extension rottlog-service-type cuirass-log-rotations) |
463995da | 168 | (service-extension activation-service-type cuirass-activation) |
a7cf4eb6 ML |
169 | (service-extension shepherd-root-service-type cuirass-shepherd-service) |
170 | (service-extension account-service-type cuirass-account))))) | |
171 |