Commit | Line | Data |
---|---|---|
a7cf4eb6 ML |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org> | |
3 | ;;; | |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
6 | ;;; GNU Guix is free software: you can redistribute it and/or modify | |
7 | ;;; it under the terms of the GNU General Public License as published by | |
8 | ;;; the Free Software Foundation, either version 3 of the License, or | |
9 | ;;; (at your option) any later version. | |
10 | ;;; | |
11 | ;;; GNU Guix is distributed in the hope that it will be useful, | |
12 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
19 | (define-module (gnu services cuirass) | |
20 | #:use-module (guix gexp) | |
21 | #:use-module (guix records) | |
22 | #:use-module (gnu packages admin) | |
23 | #:autoload (gnu packages ci) (cuirass) | |
24 | #:use-module (gnu services) | |
25 | #:use-module (gnu services base) | |
26 | #:use-module (gnu services shepherd) | |
27 | #:use-module (gnu system shadow) | |
28 | #:export (<cuirass-configuration> | |
29 | cuirass-configuration | |
30 | cuirass-configuration? | |
31 | ||
32 | cuirass-service-type | |
33 | cuirass-service)) | |
34 | ||
35 | ;;;; Commentary: | |
36 | ;;; | |
37 | ;;; This module implements a service that to run instances of Cuirass, a | |
38 | ;;; continuous integration tool. | |
39 | ;;; | |
40 | ;;;; Code: | |
41 | ||
42 | (define-record-type* <cuirass-configuration> | |
43 | cuirass-configuration make-cuirass-configuration | |
44 | cuirass-configuration? | |
b17e326f LC |
45 | (log-file cuirass-configuration-log-file ;string |
46 | (default "/var/log/cuirass.log")) | |
a7cf4eb6 ML |
47 | (cache-directory cuirass-configuration-cache-directory ;string (dir-name) |
48 | (default "")) | |
49 | (user cuirass-configuration-user ;string | |
50 | (default "cuirass")) | |
51 | (group cuirass-configuration-group ;string | |
52 | (default "cuirass")) | |
53 | (interval cuirass-configuration-interval ;integer (seconds) | |
54 | (default 60)) | |
55 | (database cuirass-configuration-database ;string (file-name) | |
56 | (default "/var/run/cuirass/cuirass.db")) | |
57aa94bd ML |
57 | (specifications cuirass-configuration-specifications ;specification-alist |
58 | (default '())) | |
a7cf4eb6 ML |
59 | (use-substitutes? cuirass-configuration-use-substitutes? ;boolean |
60 | (default #f)) | |
61 | (one-shot? cuirass-configuration-one-shot? ;boolean | |
62 | (default #f))) | |
63 | ||
64 | (define (cuirass-shepherd-service config) | |
65 | "Return a <shepherd-service> for the Cuirass service with CONFIG." | |
66 | (and | |
67 | (cuirass-configuration? config) | |
68 | (let ((cache-directory (cuirass-configuration-cache-directory config)) | |
b17e326f | 69 | (log-file (cuirass-configuration-log-file config)) |
831071b8 LC |
70 | (user (cuirass-configuration-user config)) |
71 | (group (cuirass-configuration-group config)) | |
a7cf4eb6 ML |
72 | (interval (cuirass-configuration-interval config)) |
73 | (database (cuirass-configuration-database config)) | |
57aa94bd | 74 | (specs (cuirass-configuration-specifications config)) |
a7cf4eb6 ML |
75 | (use-substitutes? (cuirass-configuration-use-substitutes? config)) |
76 | (one-shot? (cuirass-configuration-one-shot? config))) | |
77 | (list (shepherd-service | |
78 | (documentation "Run Cuirass.") | |
79 | (provision '(cuirass)) | |
80 | (requirement '(guix-daemon)) | |
81 | (start #~(make-forkexec-constructor | |
82 | (list (string-append #$cuirass "/bin/cuirass") | |
83 | #$@(if (string=? "" cache-directory) | |
84 | '() | |
85 | (list "--cache-directory" cache-directory)) | |
57aa94bd | 86 | #$@(if (null? specs) |
a7cf4eb6 | 87 | '() |
57aa94bd ML |
88 | (let ((str (format #f "'~S" specs))) |
89 | (list "--specifications" | |
90 | (plain-file "specs.scm" str)))) | |
a7cf4eb6 ML |
91 | "--database" #$database |
92 | "--interval" #$(number->string interval) | |
93 | #$@(if use-substitutes? '("--use-substitutes") '()) | |
b17e326f | 94 | #$@(if one-shot? '("--one-shot") '())) |
831071b8 LC |
95 | #:user #$user |
96 | #:group #$group | |
b17e326f | 97 | #:log-file #$log-file)) |
a7cf4eb6 ML |
98 | (stop #~(make-kill-destructor))))))) |
99 | ||
100 | (define (cuirass-account config) | |
101 | "Return the user accounts and user groups for CONFIG." | |
102 | (let ((cuirass-user (cuirass-configuration-user config)) | |
103 | (cuirass-group (cuirass-configuration-group config))) | |
104 | (list (user-group | |
105 | (name cuirass-group) | |
106 | (system? #t)) | |
107 | (user-account | |
108 | (name cuirass-user) | |
109 | (group cuirass-group) | |
110 | (system? #t) | |
111 | (comment "Cuirass privilege separation user") | |
112 | (home-directory (string-append "/var/run/" cuirass-user)) | |
113 | (shell #~(string-append #$shadow "/sbin/nologin")))))) | |
114 | ||
115 | (define cuirass-service-type | |
116 | (service-type | |
117 | (name 'cuirass) | |
118 | (extensions | |
119 | (list | |
120 | (service-extension shepherd-root-service-type cuirass-shepherd-service) | |
121 | (service-extension account-service-type cuirass-account))))) | |
122 | ||
123 | (define* (cuirass-service #:key (config (cuirass-configuration))) | |
124 | "Return a service that runs cuirass according to CONFIG." | |
125 | (service cuirass-service-type config)) |