2021-03-09 03:18:52 +00:00
|
|
|
{ lib, callPackage, fetchFromGitHub }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
rec {
|
|
|
|
dockerGen = {
|
|
|
|
version, rev, sha256
|
2021-03-09 03:18:52 +00:00
|
|
|
, moby-src
|
2020-04-24 23:36:52 +00:00
|
|
|
, runcRev, runcSha256
|
|
|
|
, containerdRev, containerdSha256
|
2021-02-05 17:12:51 +00:00
|
|
|
, tiniRev, tiniSha256, buildxSupport ? false
|
|
|
|
# package dependencies
|
2021-05-29 03:34:57 +00:00
|
|
|
, stdenv, fetchFromGitHub, buildGoPackage
|
2021-06-28 23:13:55 +00:00
|
|
|
, makeWrapper, installShellFiles, pkg-config, glibc
|
2021-02-05 17:12:51 +00:00
|
|
|
, go-md2man, go, containerd, runc, docker-proxy, tini, libtool
|
2021-04-05 15:23:46 +00:00
|
|
|
, sqlite, iproute2, lvm2, systemd, docker-buildx
|
2021-02-05 17:12:51 +00:00
|
|
|
, btrfs-progs, iptables, e2fsprogs, xz, util-linux, xfsprogs, git
|
|
|
|
, procps, libseccomp
|
|
|
|
, nixosTests
|
2021-05-28 09:39:13 +00:00
|
|
|
, clientOnly ? !stdenv.isLinux
|
2021-02-05 17:12:51 +00:00
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
let
|
|
|
|
docker-runc = runc.overrideAttrs (oldAttrs: {
|
|
|
|
name = "docker-runc-${version}";
|
|
|
|
inherit version;
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "opencontainers";
|
|
|
|
repo = "runc";
|
|
|
|
rev = runcRev;
|
|
|
|
sha256 = runcSha256;
|
|
|
|
};
|
|
|
|
# docker/runc already include these patches / are not applicable
|
|
|
|
patches = [];
|
|
|
|
});
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
docker-containerd = containerd.overrideAttrs (oldAttrs: {
|
2020-04-24 23:36:52 +00:00
|
|
|
name = "docker-containerd-${version}";
|
|
|
|
inherit version;
|
|
|
|
src = fetchFromGitHub {
|
2020-10-27 00:29:36 +00:00
|
|
|
owner = "containerd";
|
2020-04-24 23:36:52 +00:00
|
|
|
repo = "containerd";
|
|
|
|
rev = containerdRev;
|
|
|
|
sha256 = containerdSha256;
|
|
|
|
};
|
2021-01-15 22:18:51 +00:00
|
|
|
buildInputs = oldAttrs.buildInputs ++ [ libseccomp ];
|
2020-04-24 23:36:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
docker-tini = tini.overrideAttrs (oldAttrs: {
|
|
|
|
name = "docker-init-${version}";
|
|
|
|
inherit version;
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "krallin";
|
|
|
|
repo = "tini";
|
|
|
|
rev = tiniRev;
|
|
|
|
sha256 = tiniSha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Do not remove static from make files as we want a static binary
|
2021-06-28 23:13:55 +00:00
|
|
|
postPatch = "";
|
|
|
|
|
|
|
|
buildInputs = [ glibc glibc.static ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
NIX_CFLAGS_COMPILE = "-DMINIMAL=ON";
|
|
|
|
});
|
2021-01-15 22:18:51 +00:00
|
|
|
|
|
|
|
moby = buildGoPackage ((optionalAttrs (stdenv.isLinux)) rec {
|
|
|
|
name = "moby-${version}";
|
|
|
|
inherit version;
|
|
|
|
inherit docker-runc docker-containerd docker-proxy docker-tini;
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
src = moby-src;
|
2021-01-15 22:18:51 +00:00
|
|
|
|
|
|
|
goPackagePath = "github.com/docker/docker";
|
|
|
|
|
|
|
|
nativeBuildInputs = [ makeWrapper pkg-config go-md2man go libtool installShellFiles ];
|
|
|
|
buildInputs = [ sqlite lvm2 btrfs-progs systemd libseccomp ];
|
|
|
|
|
2021-04-05 15:23:46 +00:00
|
|
|
extraPath = optionals (stdenv.isLinux) (makeBinPath [ iproute2 iptables e2fsprogs xz xfsprogs procps util-linux git ]);
|
2021-01-15 22:18:51 +00:00
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
export GOCACHE="$TMPDIR/go-cache"
|
|
|
|
# build engine
|
|
|
|
cd ./go/src/${goPackagePath}
|
|
|
|
export AUTO_GOPATH=1
|
|
|
|
export DOCKER_GITCOMMIT="${rev}"
|
|
|
|
export VERSION="${version}"
|
|
|
|
./hack/make.sh dynbinary
|
|
|
|
cd -
|
|
|
|
'';
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
patchShebangs .
|
|
|
|
substituteInPlace ./hack/make.sh --replace libsystemd-journal libsystemd
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
cd ./go/src/${goPackagePath}
|
|
|
|
install -Dm755 ./bundles/dynbinary-daemon/dockerd $out/libexec/docker/dockerd
|
|
|
|
|
|
|
|
makeWrapper $out/libexec/docker/dockerd $out/bin/dockerd \
|
|
|
|
--prefix PATH : "$out/libexec/docker:$extraPath"
|
|
|
|
|
|
|
|
ln -s ${docker-containerd}/bin/containerd $out/libexec/docker/containerd
|
|
|
|
ln -s ${docker-containerd}/bin/containerd-shim $out/libexec/docker/containerd-shim
|
|
|
|
ln -s ${docker-runc}/bin/runc $out/libexec/docker/runc
|
|
|
|
ln -s ${docker-proxy}/bin/docker-proxy $out/libexec/docker/docker-proxy
|
|
|
|
ln -s ${docker-tini}/bin/tini-static $out/libexec/docker/docker-init
|
|
|
|
|
|
|
|
# systemd
|
|
|
|
install -Dm644 ./contrib/init/systemd/docker.service $out/etc/systemd/system/docker.service
|
2021-04-26 19:14:03 +00:00
|
|
|
substituteInPlace $out/etc/systemd/system/docker.service --replace /usr/bin/dockerd $out/bin/dockerd
|
|
|
|
install -Dm644 ./contrib/init/systemd/docker.socket $out/etc/systemd/system/docker.socket
|
2021-01-15 22:18:51 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
DOCKER_BUILDTAGS = []
|
|
|
|
++ optional (systemd != null) [ "journald" ]
|
|
|
|
++ optional (btrfs-progs == null) "exclude_graphdriver_btrfs"
|
|
|
|
++ optional (lvm2 == null) "exclude_graphdriver_devicemapper"
|
|
|
|
++ optional (libseccomp != null) "seccomp";
|
|
|
|
});
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
2021-05-28 09:39:13 +00:00
|
|
|
buildGoPackage ((optionalAttrs (!clientOnly) {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
inherit docker-runc docker-containerd docker-proxy docker-tini moby;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
}) // rec {
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit version rev;
|
|
|
|
|
2021-05-29 03:34:57 +00:00
|
|
|
pname = "docker";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "docker";
|
2021-01-15 22:18:51 +00:00
|
|
|
repo = "cli";
|
2020-04-24 23:36:52 +00:00
|
|
|
rev = "v${version}";
|
|
|
|
sha256 = sha256;
|
|
|
|
};
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
goPackagePath = "github.com/docker/cli";
|
2020-09-25 04:45:31 +00:00
|
|
|
|
2021-04-12 18:23:04 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
makeWrapper pkg-config go-md2man go libtool installShellFiles
|
|
|
|
];
|
2021-05-28 09:39:13 +00:00
|
|
|
buildInputs = optionals (!clientOnly) [
|
2020-04-24 23:36:52 +00:00
|
|
|
sqlite lvm2 btrfs-progs systemd libseccomp
|
2021-02-05 17:12:51 +00:00
|
|
|
] ++ optionals (buildxSupport) [ docker-buildx ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
# Keep eyes on BUILDTIME format - https://github.com/docker/cli/blob/${version}/scripts/build/.variables
|
2020-04-24 23:36:52 +00:00
|
|
|
buildPhase = ''
|
|
|
|
export GOCACHE="$TMPDIR/go-cache"
|
2021-01-15 22:18:51 +00:00
|
|
|
|
|
|
|
cd ./go/src/${goPackagePath}
|
2020-04-24 23:36:52 +00:00
|
|
|
# Mimic AUTO_GOPATH
|
|
|
|
mkdir -p .gopath/src/github.com/docker/
|
|
|
|
ln -sf $PWD .gopath/src/github.com/docker/cli
|
|
|
|
export GOPATH="$PWD/.gopath:$GOPATH"
|
|
|
|
export GITCOMMIT="${rev}"
|
|
|
|
export VERSION="${version}"
|
2021-01-15 22:18:51 +00:00
|
|
|
export BUILDTIME="1970-01-01T00:00:00Z"
|
2020-04-24 23:36:52 +00:00
|
|
|
source ./scripts/build/.variables
|
|
|
|
export CGO_ENABLED=1
|
|
|
|
go build -tags pkcs11 --ldflags "$LDFLAGS" github.com/docker/cli/cmd/docker
|
|
|
|
cd -
|
|
|
|
'';
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
postPatch = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
patchShebangs .
|
2021-01-15 22:18:51 +00:00
|
|
|
substituteInPlace ./scripts/build/.variables --replace "set -eu" ""
|
2021-02-05 17:12:51 +00:00
|
|
|
'' + optionalString buildxSupport ''
|
|
|
|
substituteInPlace ./cli-plugins/manager/manager_unix.go --replace /usr/libexec/docker/cli-plugins \
|
|
|
|
${lib.strings.makeSearchPathOutput "bin" "libexec/docker/cli-plugins" [docker-buildx]}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
outputs = ["out" "man"];
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
installPhase = ''
|
|
|
|
cd ./go/src/${goPackagePath}
|
2021-01-15 22:18:51 +00:00
|
|
|
install -Dm755 ./docker $out/libexec/docker/docker
|
2020-09-25 04:45:31 +00:00
|
|
|
|
|
|
|
makeWrapper $out/libexec/docker/docker $out/bin/docker \
|
|
|
|
--prefix PATH : "$out/libexec/docker:$extraPath"
|
2021-05-28 09:39:13 +00:00
|
|
|
'' + optionalString (!clientOnly) ''
|
2021-01-15 22:18:51 +00:00
|
|
|
# symlink docker daemon to docker cli derivation
|
|
|
|
ln -s ${moby}/bin/dockerd $out/bin/dockerd
|
2021-04-26 19:14:03 +00:00
|
|
|
|
|
|
|
# systemd
|
|
|
|
mkdir -p $out/etc/systemd/system
|
|
|
|
ln -s ${moby}/etc/systemd/system/docker.service $out/etc/systemd/system/docker.service
|
|
|
|
ln -s ${moby}/etc/systemd/system/docker.socket $out/etc/systemd/system/docker.socket
|
2020-04-24 23:36:52 +00:00
|
|
|
'' + ''
|
|
|
|
# completion (cli)
|
2021-01-15 22:18:51 +00:00
|
|
|
installShellCompletion --bash ./contrib/completion/bash/docker
|
|
|
|
installShellCompletion --fish ./contrib/completion/fish/docker.fish
|
|
|
|
installShellCompletion --zsh ./contrib/completion/zsh/_docker
|
2020-09-25 04:45:31 +00:00
|
|
|
'' + lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
|
2020-04-24 23:36:52 +00:00
|
|
|
# Generate man pages from cobra commands
|
|
|
|
echo "Generate man pages from cobra"
|
|
|
|
mkdir -p ./man/man1
|
|
|
|
go build -o ./gen-manpages github.com/docker/cli/man
|
|
|
|
./gen-manpages --root . --target ./man/man1
|
2020-09-25 04:45:31 +00:00
|
|
|
'' + ''
|
2020-04-24 23:36:52 +00:00
|
|
|
# Generate legacy pages from markdown
|
|
|
|
echo "Generate legacy manpages"
|
|
|
|
./man/md2man-all.sh -q
|
|
|
|
|
2020-05-15 21:57:56 +00:00
|
|
|
installManPage man/*/*.[1-9]
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2021-05-28 09:39:13 +00:00
|
|
|
passthru.tests = lib.optionals (!clientOnly) { inherit (nixosTests) docker; };
|
2020-11-24 20:58:05 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
meta = {
|
|
|
|
homepage = "https://www.docker.com/";
|
|
|
|
description = "An open source project to pack, ship and run any application as a lightweight container";
|
|
|
|
license = licenses.asl20;
|
2020-10-11 12:50:04 +00:00
|
|
|
maintainers = with maintainers; [ offline tailhook vdemeester periklis ];
|
2020-04-24 23:36:52 +00:00
|
|
|
platforms = with platforms; linux ++ darwin;
|
|
|
|
};
|
2021-03-09 03:18:52 +00:00
|
|
|
|
|
|
|
# Exposed for tarsum build on non-linux systems (build-support/docker/default.nix)
|
|
|
|
inherit moby-src;
|
2020-04-24 23:36:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
# Get revisions from
|
2021-01-15 22:18:51 +00:00
|
|
|
# https://github.com/moby/moby/tree/${version}/hack/dockerfile/install/*
|
2021-02-05 17:12:51 +00:00
|
|
|
docker_20_10 = callPackage dockerGen rec {
|
2021-05-29 03:34:57 +00:00
|
|
|
version = "20.10.6";
|
2020-07-18 16:06:22 +00:00
|
|
|
rev = "v${version}";
|
2021-05-29 03:34:57 +00:00
|
|
|
sha256 = "15kknb26vyzjgqmn8r81a1sy1i5br6bvngqd5xljihppnxvp2gvl";
|
2021-03-09 03:18:52 +00:00
|
|
|
moby-src = fetchFromGitHub {
|
|
|
|
owner = "moby";
|
|
|
|
repo = "moby";
|
|
|
|
rev = "v${version}";
|
2021-05-29 03:34:57 +00:00
|
|
|
sha256 = "1l4ra9bsvydaxd2fy7dgxp7ynpp0mrlwvcdhxiafw596559ab6qk";
|
2021-03-09 03:18:52 +00:00
|
|
|
};
|
2021-05-29 03:34:57 +00:00
|
|
|
runcRev = "b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7"; # v1.0.0-rc95
|
|
|
|
runcSha256 = "18sbvmlvb6kird4w3rqsfrjdj7n25firabvdxsl0rxjfy9r1g2xb";
|
|
|
|
containerdRev = "12dca9790f4cb6b18a6a7a027ce420145cb98ee7"; # v1.5.1
|
|
|
|
containerdSha256 = "16q34yiv5q98b9d5vgy1lmmppg8agrmnfd1kzpakkf4czkws0p4d";
|
2021-01-15 22:18:51 +00:00
|
|
|
tiniRev = "de40ad007797e0dcd8b7126f27bb87401d224240"; # v0.19.0
|
2020-04-24 23:36:52 +00:00
|
|
|
tiniSha256 = "1h20i3wwlbd8x4jr2gz68hgklh0lb0jj7y5xk1wvr8y58fip1rdn";
|
|
|
|
};
|
|
|
|
}
|