1 { lib, callPackage, fetchFromGitHub }:
9 , containerdRev, containerdHash
11 , buildxSupport ? true, composeSupport ? true, sbomSupport ? false
12 # package dependencies
13 , stdenv, fetchFromGitHub, fetchpatch, buildGoPackage
14 , makeWrapper, installShellFiles, pkg-config, glibc
15 , go-md2man, go, containerd, runc, tini, libtool
16 , sqlite, iproute2, docker-buildx, docker-compose, docker-sbom
17 , iptables, e2fsprogs, xz, util-linux, xfsprogs, git
18 , procps, rootlesskit, slirp4netns, fuse-overlayfs, nixosTests
19 , clientOnly ? !stdenv.isLinux, symlinkJoin
20 , withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd, systemd
21 , withBtrfs ? stdenv.isLinux, btrfs-progs
22 , withLvm ? stdenv.isLinux, lvm2
23 , withSeccomp ? stdenv.isLinux, libseccomp
26 docker-runc = runc.overrideAttrs (oldAttrs: {
27 pname = "docker-runc";
30 src = fetchFromGitHub {
31 owner = "opencontainers";
37 # docker/runc already include these patches / are not applicable
41 docker-containerd = containerd.overrideAttrs (oldAttrs: {
42 pname = "docker-containerd";
45 src = fetchFromGitHub {
49 hash = containerdHash;
52 buildInputs = oldAttrs.buildInputs
53 ++ lib.optionals withSeccomp [ libseccomp ];
56 docker-tini = tini.overrideAttrs (oldAttrs: {
57 pname = "docker-init";
60 src = fetchFromGitHub {
67 # Do not remove static from make files as we want a static binary
70 buildInputs = [ glibc glibc.static ];
72 env.NIX_CFLAGS_COMPILE = "-DMINIMAL=ON";
75 moby-src = fetchFromGitHub {
82 moby = buildGoPackage (lib.optionalAttrs stdenv.isLinux rec {
88 goPackagePath = "github.com/docker/docker";
90 nativeBuildInputs = [ makeWrapper pkg-config go-md2man go libtool installShellFiles ];
91 buildInputs = [ sqlite ]
92 ++ lib.optional withLvm lvm2
93 ++ lib.optional withBtrfs btrfs-progs
94 ++ lib.optional withSystemd systemd
95 ++ lib.optional withSeccomp libseccomp;
97 extraPath = lib.optionals stdenv.isLinux (lib.makeBinPath [ iproute2 iptables e2fsprogs xz xfsprogs procps util-linux git ]);
99 extraUserPath = lib.optionals (stdenv.isLinux && !clientOnly) (lib.makeBinPath [ rootlesskit slirp4netns fuse-overlayfs ]);
101 patches = lib.optionals (lib.versionOlder version "23") [
102 # This patch incorporates code from a PR fixing using buildkit with the ZFS graph driver.
103 # It could be removed when a version incorporating this patch is released.
105 name = "buildkit-zfs.patch";
106 url = "https://github.com/moby/moby/pull/43136.patch";
107 hash = "sha256-1WZfpVnnqFwLMYqaHLploOodls0gHF8OCp7MrM26iX8=";
109 ] ++ lib.optionals (lib.versions.major version == "24") [
110 # docker_24 has LimitNOFILE set to "infinity", which causes a wide variety of issues in containers.
111 # Issues range from higher-than-usual ressource usage, to containers not starting at all.
112 # This patch (part of the release candidates for docker_25) simply removes this unit option
113 # making systemd use its default "1024:524288", which is sane. See commit message and/or the PR for
114 # more details: https://github.com/moby/moby/pull/45534
116 name = "LimitNOFILE-systemd-default.patch";
117 url = "https://github.com/moby/moby/pull/45534/commits/c8930105bc9fc3c1a8a90886c23535cc6c41e130.patch";
118 hash = "sha256-nyGLxFrJaD0TrDqsAwOD6Iph0aHcFH9sABj1Fy74sec=";
123 patchShebangs hack/make.sh hack/make/ hack/with-go-mod.sh
127 export GOCACHE="$TMPDIR/go-cache"
129 cd ./go/src/${goPackagePath}
131 export DOCKER_GITCOMMIT="${cliRev}"
132 export VERSION="${version}"
133 ./hack/make.sh dynbinary
138 cd ./go/src/${goPackagePath}
139 install -Dm755 ./bundles/dynbinary-daemon/dockerd $out/libexec/docker/dockerd
140 install -Dm755 ./bundles/dynbinary-daemon/docker-proxy $out/libexec/docker/docker-proxy
142 makeWrapper $out/libexec/docker/dockerd $out/bin/dockerd \
143 --prefix PATH : "$out/libexec/docker:$extraPath"
145 ln -s ${docker-containerd}/bin/containerd $out/libexec/docker/containerd
146 ln -s ${docker-containerd}/bin/containerd-shim $out/libexec/docker/containerd-shim
147 ln -s ${docker-runc}/bin/runc $out/libexec/docker/runc
148 ln -s ${docker-tini}/bin/tini-static $out/libexec/docker/docker-init
151 install -Dm644 ./contrib/init/systemd/docker.service $out/etc/systemd/system/docker.service
152 substituteInPlace $out/etc/systemd/system/docker.service --replace /usr/bin/dockerd $out/bin/dockerd
153 install -Dm644 ./contrib/init/systemd/docker.socket $out/etc/systemd/system/docker.socket
156 install -Dm755 ./contrib/dockerd-rootless.sh $out/libexec/docker/dockerd-rootless.sh
157 makeWrapper $out/libexec/docker/dockerd-rootless.sh $out/bin/dockerd-rootless \
158 --prefix PATH : "$out/libexec/docker:$extraPath:$extraUserPath"
161 DOCKER_BUILDTAGS = lib.optional withSystemd "journald"
162 ++ lib.optional (!withBtrfs) "exclude_graphdriver_btrfs"
163 ++ lib.optional (!withLvm) "exclude_graphdriver_devicemapper"
164 ++ lib.optional withSeccomp "seccomp";
167 plugins = lib.optional buildxSupport docker-buildx
168 ++ lib.optional composeSupport docker-compose
169 ++ lib.optional sbomSupport docker-sbom;
170 pluginsRef = symlinkJoin { name = "docker-plugins"; paths = plugins; };
172 buildGoPackage (lib.optionalAttrs (!clientOnly) {
173 # allow overrides of docker components
174 # TODO: move packages out of the let...in into top-level to allow proper overrides
175 inherit docker-runc docker-containerd docker-tini moby;
180 src = fetchFromGitHub {
187 goPackagePath = "github.com/docker/cli";
189 nativeBuildInputs = [
190 makeWrapper pkg-config go-md2man go libtool installShellFiles
193 buildInputs = plugins ++ lib.optionals (lib.versionAtLeast version "23" && stdenv.isLinux) [
199 patchShebangs man scripts/build/
200 substituteInPlace ./scripts/build/.variables --replace "set -eu" ""
201 '' + lib.optionalString (plugins != []) ''
202 substituteInPlace ./cli-plugins/manager/manager_unix.go --replace /usr/libexec/docker/cli-plugins \
203 "${pluginsRef}/libexec/docker/cli-plugins"
206 # Keep eyes on BUILDTIME format - https://github.com/docker/cli/blob/${version}/scripts/build/.variables
208 export GOCACHE="$TMPDIR/go-cache"
210 cd ./go/src/${goPackagePath}
212 mkdir -p .gopath/src/github.com/docker/
213 ln -sf $PWD .gopath/src/github.com/docker/cli
214 export GOPATH="$PWD/.gopath:$GOPATH"
215 export GITCOMMIT="${cliRev}"
216 export VERSION="${version}"
217 export BUILDTIME="1970-01-01T00:00:00Z"
218 source ./scripts/build/.variables
220 go build -tags pkcs11 --ldflags "$GO_LDFLAGS" github.com/docker/cli/cmd/docker
224 outputs = ["out"] ++ lib.optional (lib.versionOlder version "23") "man";
227 cd ./go/src/${goPackagePath}
228 install -Dm755 ./docker $out/libexec/docker/docker
230 makeWrapper $out/libexec/docker/docker $out/bin/docker \
231 --prefix PATH : "$out/libexec/docker:$extraPath"
232 '' + lib.optionalString (!clientOnly) ''
233 # symlink docker daemon to docker cli derivation
234 ln -s ${moby}/bin/dockerd $out/bin/dockerd
235 ln -s ${moby}/bin/dockerd-rootless $out/bin/dockerd-rootless
238 mkdir -p $out/etc/systemd/system
239 ln -s ${moby}/etc/systemd/system/docker.service $out/etc/systemd/system/docker.service
240 ln -s ${moby}/etc/systemd/system/docker.socket $out/etc/systemd/system/docker.socket
243 installShellCompletion --bash ./contrib/completion/bash/docker
244 installShellCompletion --fish ./contrib/completion/fish/docker.fish
245 installShellCompletion --zsh ./contrib/completion/zsh/_docker
246 '' + lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform && lib.versionOlder version "23") ''
247 # Generate man pages from cobra commands
248 echo "Generate man pages from cobra"
250 go build -o ./gen-manpages github.com/docker/cli/man
251 ./gen-manpages --root . --target ./man/man1
252 '' + lib.optionalString (lib.versionOlder version "23") ''
253 # Generate legacy pages from markdown
254 echo "Generate legacy manpages"
255 ./man/md2man-all.sh -q
257 installManPage man/*/*.[1-9]
261 # Exposed for tarsum build on non-linux systems (build-support/docker/default.nix)
263 tests = lib.optionals (!clientOnly) { inherit (nixosTests) docker; };
267 homepage = "https://www.docker.com/";
268 description = "An open source project to pack, ship and run any application as a lightweight container";
270 Docker is a platform designed to help developers build, share, and run modern applications.
272 To enable the docker daemon on NixOS, set the `virtualisation.docker.enable` option to `true`.
274 license = licenses.asl20;
275 maintainers = with maintainers; [ offline vdemeester periklis ];
276 mainProgram = "docker";
281 # https://github.com/moby/moby/tree/${version}/hack/dockerfile/install/*
282 docker_24 = callPackage dockerGen rec {
284 cliRev = "v${version}";
285 cliHash = "sha256-u1quVGTx/p8BDyRn33vYyyuE5BOhWMnGQ5uVX0PZ5mg=";
286 mobyRev = "v${version}";
287 mobyHash = "sha256-JQjRz1fHZlQRkNw/R8WWLV8caN3/U3mrKKQXbZt2crU=";
289 runcHash = "sha256-rDJYEc64KW4Qa3Eg2oUjJqIKrg6THb5hxQFFbvb9Zp4=";
290 containerdRev = "v1.7.1";
291 containerdHash = "sha256-WwedtcsrDQwMQcKFO5nnPiHyGJpl5hXZlmpbBe1/ftY=";
293 tiniHash = "sha256-ZDKu/8yE5G0RYFJdhgmCdN3obJNyRWv6K/Gd17zc1sI=";
296 docker_25 = callPackage dockerGen rec {
298 cliRev = "v${version}";
299 cliHash = "sha256-CACMi3bXUN6oGc2f/Z+lNQqMgQ4llRWPRKgijdpiPGg=";
300 mobyRev = "v${version}";
301 mobyHash = "sha256-4QGz22fXxyAD77pyUWb2lF3VKqxmPIrGqcJGoyrEHew=";
303 runcHash = "sha256-N77CU5XiGYIdwQNPFyluXjseTeaYuNJ//OsEUS0g/v0=";
304 containerdRev = "v1.7.13";
305 containerdHash = "sha256-y3CYDZbA2QjIn1vyq/p1F1pAVxQHi/0a6hGWZCRWzyk=";
307 tiniHash = "sha256-ZDKu/8yE5G0RYFJdhgmCdN3obJNyRWv6K/Gd17zc1sI=";
310 docker_26 = callPackage dockerGen rec {
312 cliRev = "v${version}";
313 cliHash = "sha256-jGg/AVnIzI8e+DdF0uKlSZApRxcwuOjCQpfnBaCY4fI=";
314 mobyRev = "v${version}";
315 mobyHash = "sha256-cDlRVdQNzH/X2SJUYHK1QLUHlKQtSyRYCVbz3wPx1ZM=";
317 runcHash = "sha256-N77CU5XiGYIdwQNPFyluXjseTeaYuNJ//OsEUS0g/v0=";
318 containerdRev = "v1.7.13";
319 containerdHash = "sha256-y3CYDZbA2QjIn1vyq/p1F1pAVxQHi/0a6hGWZCRWzyk=";
321 tiniHash = "sha256-ZDKu/8yE5G0RYFJdhgmCdN3obJNyRWv6K/Gd17zc1sI=";