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 | ||
7a31d93a MC |
34 | ;;; We're not using serialize-configuration, but we must define this because |
35 | ;;; the define-configuration macro validates it exists. | |
36 | (define (serialize-boolean field-name val) | |
37 | "") | |
38 | ||
8af4c335 DM |
39 | (define-configuration docker-configuration |
40 | (docker | |
41 | (package docker) | |
42 | "Docker daemon package.") | |
43 | (containerd | |
44 | (package containerd) | |
7a31d93a MC |
45 | "containerd package.") |
46 | (proxy | |
47 | (package docker-libnetwork-cmd-proxy) | |
48 | "The proxy package to support inter-container and outside-container | |
49 | loop-back communications.") | |
50 | (enable-proxy? | |
51 | (boolean #t) | |
52 | "Enable or disable the user-land proxy (enabled by default).")) | |
8af4c335 DM |
53 | |
54 | (define %docker-accounts | |
55 | (list (user-group (name "docker") (system? #t)))) | |
56 | ||
57 | (define (%containerd-activation config) | |
58 | (let ((state-dir "/var/lib/containerd")) | |
59 | #~(begin | |
60 | (use-modules (guix build utils)) | |
61 | (mkdir-p #$state-dir)))) | |
62 | ||
63 | (define (%docker-activation config) | |
64 | (%containerd-activation config) | |
65 | (let ((state-dir "/var/lib/docker")) | |
66 | #~(begin | |
67 | (use-modules (guix build utils)) | |
68 | (mkdir-p #$state-dir)))) | |
69 | ||
70 | (define (containerd-shepherd-service config) | |
71 | (let* ((package (docker-configuration-containerd config))) | |
72 | (shepherd-service | |
73 | (documentation "containerd daemon.") | |
74 | (provision '(containerd)) | |
75 | (start #~(make-forkexec-constructor | |
f0bfd0fc DM |
76 | (list (string-append #$package "/bin/containerd")) |
77 | #:log-file "/var/log/containerd.log")) | |
8af4c335 DM |
78 | (stop #~(make-kill-destructor))))) |
79 | ||
80 | (define (docker-shepherd-service config) | |
7a31d93a MC |
81 | (let* ((docker (docker-configuration-docker config)) |
82 | (enable-proxy? (docker-configuration-enable-proxy? config)) | |
83 | (proxy (docker-configuration-proxy config))) | |
8af4c335 DM |
84 | (shepherd-service |
85 | (documentation "Docker daemon.") | |
86 | (provision '(dockerd)) | |
8b0c1744 | 87 | (requirement '(containerd |
1c84e68b DM |
88 | dbus-system |
89 | elogind | |
8b0c1744 DM |
90 | file-system-/sys/fs/cgroup/blkio |
91 | file-system-/sys/fs/cgroup/cpu | |
92 | file-system-/sys/fs/cgroup/cpuset | |
93 | file-system-/sys/fs/cgroup/devices | |
94 | file-system-/sys/fs/cgroup/memory | |
95 | ; TODO: file-system-/sys/fs/cgroup/pids | |
1c84e68b DM |
96 | networking |
97 | udev)) | |
8af4c335 DM |
98 | (start #~(make-forkexec-constructor |
99 | (list (string-append #$docker "/bin/dockerd") | |
7a31d93a MC |
100 | "-p" "/var/run/docker.pid" |
101 | (if #$enable-proxy? "--userland-proxy" "") | |
102 | "--userland-proxy-path" (string-append #$proxy | |
103 | "/bin/proxy")) | |
8af4c335 DM |
104 | #:pid-file "/var/run/docker.pid" |
105 | #:log-file "/var/log/docker.log")) | |
106 | (stop #~(make-kill-destructor))))) | |
107 | ||
108 | (define docker-service-type | |
109 | (service-type (name 'docker) | |
110 | (description "Provide capability to run Docker application | |
111 | bundles in Docker containers.") | |
112 | (extensions | |
113 | (list | |
114 | (service-extension activation-service-type | |
115 | %docker-activation) | |
116 | (service-extension shepherd-root-service-type | |
d3a0e74d DM |
117 | (lambda (config) |
118 | (list (containerd-shepherd-service config) | |
119 | (docker-shepherd-service config)))) | |
8af4c335 DM |
120 | (service-extension account-service-type |
121 | (const %docker-accounts)))) | |
122 | (default-value (docker-configuration)))) |