1{ stdenv, lib, fetchFromGitHub, makeWrapper, removeReferencesTo, pkgconfig
2, go-md2man, go, containerd, runc, docker-proxy, tini, libtool
3, sqlite, iproute, bridge-utils, devicemapper, systemd
4, btrfs-progs, iptables, e2fsprogs, xz, utillinux, xfsprogs
5, procps, libseccomp
6}:
7
8with lib;
9
10rec {
11 dockerGen = {
12 version, rev, sha256
13 , runcRev, runcSha256
14 , containerdRev, containerdSha256
15 , tiniRev, tiniSha256
16 } :
17 let
18 docker-runc = runc.overrideAttrs (oldAttrs: rec {
19 name = "docker-runc";
20 src = fetchFromGitHub {
21 owner = "docker";
22 repo = "runc";
23 rev = runcRev;
24 sha256 = runcSha256;
25 };
26 # docker/runc already include these patches / are not applicable
27 patches = [];
28 });
29
30 docker-containerd = containerd.overrideAttrs (oldAttrs: rec {
31 name = "docker-containerd";
32 src = fetchFromGitHub {
33 owner = "docker";
34 repo = "containerd";
35 rev = containerdRev;
36 sha256 = containerdSha256;
37 };
38
39 hardeningDisable = [ "fortify" ];
40
41 buildInputs = [ removeReferencesTo go btrfs-progs ];
42 });
43
44 docker-tini = tini.overrideAttrs (oldAttrs: rec {
45 name = "docker-init";
46 src = fetchFromGitHub {
47 owner = "krallin";
48 repo = "tini";
49 rev = tiniRev;
50 sha256 = tiniSha256;
51 };
52
53 # Do not remove static from make files as we want a static binary
54 patchPhase = ''
55 '';
56
57 NIX_CFLAGS_COMPILE = [
58 "-DMINIMAL=ON"
59 ];
60 });
61 in
62 stdenv.mkDerivation ((optionalAttrs (stdenv.isLinux) rec {
63
64 inherit docker-runc docker-containerd docker-proxy docker-tini;
65
66 DOCKER_BUILDTAGS = []
67 ++ optional (systemd != null) [ "journald" ]
68 ++ optional (btrfs-progs == null) "exclude_graphdriver_btrfs"
69 ++ optional (devicemapper == null) "exclude_graphdriver_devicemapper"
70 ++ optional (libseccomp != null) "seccomp";
71
72 }) // rec {
73 inherit version rev;
74
75 name = "docker-${version}";
76
77 src = fetchFromGitHub {
78 owner = "docker";
79 repo = "docker-ce";
80 rev = "v${version}";
81 sha256 = sha256;
82 };
83
84 # Optimizations break compilation of libseccomp c bindings
85 hardeningDisable = [ "fortify" ];
86
87 nativeBuildInputs = [ pkgconfig ];
88 buildInputs = [
89 makeWrapper removeReferencesTo go-md2man go libtool
90 ] ++ optionals (stdenv.isLinux) [
91 sqlite devicemapper btrfs-progs systemd libseccomp
92 ];
93
94 dontStrip = true;
95
96 buildPhase = (optionalString (stdenv.isLinux) ''
97 # build engine
98 cd ./components/engine
99 export AUTO_GOPATH=1
100 export DOCKER_GITCOMMIT="${rev}"
101 export VERSION="${version}"
102 ./hack/make.sh dynbinary
103 cd -
104 '') + ''
105 # build cli
106 cd ./components/cli
107 # Mimic AUTO_GOPATH
108 mkdir -p .gopath/src/github.com/docker/
109 ln -sf $PWD .gopath/src/github.com/docker/cli
110 export GOPATH="$PWD/.gopath:$GOPATH"
111 export GITCOMMIT="${rev}"
112 export VERSION="${version}"
113 source ./scripts/build/.variables
114 export CGO_ENABLED=1
115 go build -tags pkcs11 --ldflags "$LDFLAGS" github.com/docker/cli/cmd/docker
116 cd -
117 '';
118
119 # systemd 230 no longer has libsystemd-journal as a separate entity from libsystemd
120 patchPhase = ''
121 substituteInPlace ./components/cli/scripts/build/.variables --replace "set -eu" ""
122 '' + optionalString (stdenv.isLinux) ''
123 patchShebangs .
124 substituteInPlace ./components/engine/hack/make.sh --replace libsystemd-journal libsystemd
125 substituteInPlace ./components/engine/daemon/logger/journald/read.go --replace libsystemd-journal libsystemd
126 '';
127
128 outputs = ["out" "man"];
129
130 extraPath = optionals (stdenv.isLinux) (makeBinPath [ iproute iptables e2fsprogs xz xfsprogs procps utillinux ]);
131
132 installPhase = optionalString (stdenv.isLinux) ''
133 install -Dm755 ./components/engine/bundles/dynbinary-daemon/dockerd $out/libexec/docker/dockerd
134
135 makeWrapper $out/libexec/docker/dockerd $out/bin/dockerd \
136 --prefix PATH : "$out/libexec/docker:$extraPath"
137
138 # docker uses containerd now
139 ln -s ${docker-containerd}/bin/containerd $out/libexec/docker/docker-containerd
140 ln -s ${docker-containerd}/bin/containerd-shim $out/libexec/docker/docker-containerd-shim
141 ln -s ${docker-runc}/bin/runc $out/libexec/docker/docker-runc
142 ln -s ${docker-proxy}/bin/docker-proxy $out/libexec/docker/docker-proxy
143 ln -s ${docker-tini}/bin/tini-static $out/libexec/docker/docker-init
144
145 # systemd
146 install -Dm644 ./components/engine/contrib/init/systemd/docker.service $out/etc/systemd/system/docker.service
147 '' + ''
148 install -Dm755 ./components/cli/docker $out/libexec/docker/docker
149
150 makeWrapper $out/libexec/docker/docker $out/bin/docker \
151 --prefix PATH : "$out/libexec/docker:$extraPath"
152
153 # completion (cli)
154 install -Dm644 ./components/cli/contrib/completion/bash/docker $out/share/bash-completion/completions/docker
155 install -Dm644 ./components/cli/contrib/completion/fish/docker.fish $out/share/fish/vendor_completions.d/docker.fish
156 install -Dm644 ./components/cli/contrib/completion/zsh/_docker $out/share/zsh/site-functions/_docker
157
158 # Include contributed man pages (cli)
159 # Generate man pages from cobra commands
160 echo "Generate man pages from cobra"
161 cd ./components/cli
162 mkdir -p ./man/man1
163 go build -o ./gen-manpages github.com/docker/cli/man
164 ./gen-manpages --root . --target ./man/man1
165
166 # Generate legacy pages from markdown
167 echo "Generate legacy manpages"
168 ./man/md2man-all.sh -q
169
170 manRoot="$man/share/man"
171 mkdir -p "$manRoot"
172 for manDir in ./man/man?; do
173 manBase="$(basename "$manDir")" # "man1"
174 for manFile in "$manDir"/*; do
175 manName="$(basename "$manFile")" # "docker-build.1"
176 mkdir -p "$manRoot/$manBase"
177 gzip -c "$manFile" > "$manRoot/$manBase/$manName.gz"
178 done
179 done
180 '';
181
182 preFixup = ''
183 find $out -type f -exec remove-references-to -t ${go} -t ${stdenv.cc.cc} '{}' +
184 '' + optionalString (stdenv.isLinux) ''
185 find $out -type f -exec remove-references-to -t ${stdenv.glibc.dev} '{}' +
186 '';
187
188 meta = {
189 homepage = https://www.docker.com/;
190 description = "An open source project to pack, ship and run any application as a lightweight container";
191 license = licenses.asl20;
192 maintainers = with maintainers; [ nequissimus offline tailhook vdemeester periklis ];
193 platforms = with platforms; linux ++ darwin;
194 };
195 });
196
197 # Get revisions from
198 # https://github.com/docker/docker-ce/blob/v${version}/components/engine/hack/dockerfile/binaries-commits
199
200 docker_17_12 = dockerGen rec {
201 version = "17.12.1-ce";
202 rev = "7390fc6103da41cf98ae66cfac80fa143268bf60"; # git commit
203 sha256 = "14pz5yqsjypjb6xiq828jrg9aq7wajrrf3mnd9109lw224p03d8i";
204 runcRev = "9f9c96235cc97674e935002fc3d78361b696a69e";
205 runcSha256 = "18f8vqdbf685dd777pjh8jzpxafw2vapqh4m43xgyi7lfwa0gsln";
206 containerdRev = "9b55aab90508bd389d7654c4baf173a981477d55";
207 containerdSha256 = "0kfafqi66yp4qy738pl11f050hfrx9m4kc670qpx7fmf9ii7q6p2";
208 tiniRev = "949e6facb77383876aeff8a6944dde66b3089574";
209 tiniSha256 = "0zj4kdis1vvc6dwn4gplqna0bs7v6d1y2zc8v80s3zi018inhznw";
210 };
211
212 docker_18_02 = dockerGen rec {
213 version = "18.02.0-ce";
214 rev = "fc4de447b563498eb4da89f56fb858bbe761d91b"; # git commit
215 sha256 = "1025cwv2niiwg5pc30nb1qky1raisvd9ix2qw6rdib232hwq9k8m";
216 runcRev = "9f9c96235cc97674e935002fc3d78361b696a69e";
217 runcSha256 = "18f8vqdbf685dd777pjh8jzpxafw2vapqh4m43xgyi7lfwa0gsln";
218 containerdRev = "9b55aab90508bd389d7654c4baf173a981477d55";
219 containerdSha256 = "0kfafqi66yp4qy738pl11f050hfrx9m4kc670qpx7fmf9ii7q6p2";
220 tiniRev = "949e6facb77383876aeff8a6944dde66b3089574";
221 tiniSha256 = "0zj4kdis1vvc6dwn4gplqna0bs7v6d1y2zc8v80s3zi018inhznw";
222 };
223}