Commit | Line | Data |
---|---|---|
8af4c335 DM |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2018 Danny Milosavljevic <dannym@scratchpost.org> | |
3 | ;;; | |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
7 | ;;; under the terms of the GNU General Public License as published by | |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
12 | ;;; 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 docker) | |
20 | #:use-module (gnu services) | |
21 | #:use-module (gnu services configuration) | |
22 | #:use-module (gnu services base) | |
23 | #:use-module (gnu services dbus) | |
24 | #:use-module (gnu services shepherd) | |
25 | #:use-module (gnu system shadow) | |
26 | #:use-module (gnu packages docker) | |
27 | #:use-module (guix records) | |
28 | #:use-module (guix gexp) | |
29 | #:use-module (guix packages) | |
30 | ||
31 | #:export (docker-configuration | |
32 | docker-service-type)) | |
33 | ||
34 | (define-configuration docker-configuration | |
35 | (docker | |
36 | (package docker) | |
37 | "Docker daemon package.") | |
38 | (containerd | |
39 | (package containerd) | |
40 | "containerd package.")) | |
41 | ||
42 | (define %docker-accounts | |
43 | (list (user-group (name "docker") (system? #t)))) | |
44 | ||
45 | (define (%containerd-activation config) | |
46 | (let ((state-dir "/var/lib/containerd")) | |
47 | #~(begin | |
48 | (use-modules (guix build utils)) | |
49 | (mkdir-p #$state-dir)))) | |
50 | ||
51 | (define (%docker-activation config) | |
52 | (%containerd-activation config) | |
53 | (let ((state-dir "/var/lib/docker")) | |
54 | #~(begin | |
55 | (use-modules (guix build utils)) | |
56 | (mkdir-p #$state-dir)))) | |
57 | ||
58 | (define (containerd-shepherd-service config) | |
59 | (let* ((package (docker-configuration-containerd config))) | |
60 | (shepherd-service | |
61 | (documentation "containerd daemon.") | |
62 | (provision '(containerd)) | |
63 | (start #~(make-forkexec-constructor | |
f0bfd0fc DM |
64 | (list (string-append #$package "/bin/containerd")) |
65 | #:log-file "/var/log/containerd.log")) | |
8af4c335 DM |
66 | (stop #~(make-kill-destructor))))) |
67 | ||
68 | (define (docker-shepherd-service config) | |
69 | (let* ((docker (docker-configuration-docker config))) | |
70 | (shepherd-service | |
71 | (documentation "Docker daemon.") | |
72 | (provision '(dockerd)) | |
8b0c1744 | 73 | (requirement '(containerd |
1c84e68b DM |
74 | dbus-system |
75 | elogind | |
8b0c1744 DM |
76 | file-system-/sys/fs/cgroup/blkio |
77 | file-system-/sys/fs/cgroup/cpu | |
78 | file-system-/sys/fs/cgroup/cpuset | |
79 | file-system-/sys/fs/cgroup/devices | |
80 | file-system-/sys/fs/cgroup/memory | |
81 | ; TODO: file-system-/sys/fs/cgroup/pids | |
1c84e68b DM |
82 | networking |
83 | udev)) | |
8af4c335 DM |
84 | (start #~(make-forkexec-constructor |
85 | (list (string-append #$docker "/bin/dockerd") | |
86 | "-p" "/var/run/docker.pid") | |
87 | #:pid-file "/var/run/docker.pid" | |
88 | #:log-file "/var/log/docker.log")) | |
89 | (stop #~(make-kill-destructor))))) | |
90 | ||
91 | (define docker-service-type | |
92 | (service-type (name 'docker) | |
93 | (description "Provide capability to run Docker application | |
94 | bundles in Docker containers.") | |
95 | (extensions | |
96 | (list | |
97 | (service-extension activation-service-type | |
98 | %docker-activation) | |
99 | (service-extension shepherd-root-service-type | |
d3a0e74d DM |
100 | (lambda (config) |
101 | (list (containerd-shepherd-service config) | |
102 | (docker-shepherd-service config)))) | |
8af4c335 DM |
103 | (service-extension account-service-type |
104 | (const %docker-accounts)))) | |
105 | (default-value (docker-configuration)))) |