nixpkgs/pkgs/applications/virtualization/docker/default.nix

234 lines
8 KiB
Nix
Raw Normal View History

{ lib, callPackage, fetchFromGitHub }:
2014-01-24 14:39:43 +01:00
2016-09-10 12:45:01 +02:00
with lib;
2015-11-16 16:17:32 +01:00
2017-04-04 14:03:55 +02:00
rec {
dockerGen = {
version, rev, sha256
, moby-src
2017-04-04 14:03:55 +02:00
, runcRev, runcSha256
, containerdRev, containerdSha256
, tiniRev, tiniSha256, buildxSupport ? false
# package dependencies
, stdenv, fetchFromGitHub, fetchpatch, buildGoPackage
, makeWrapper, installShellFiles, pkg-config
, go-md2man, go, containerd, runc, docker-proxy, tini, libtool
2021-03-14 17:05:16 +01:00
, sqlite, iproute2, lvm2, systemd, docker-buildx
, btrfs-progs, iptables, e2fsprogs, xz, util-linux, xfsprogs, git
, procps, libseccomp
, nixosTests
}:
2017-11-16 12:48:28 +01:00
let
2019-08-13 23:52:01 +02:00
docker-runc = runc.overrideAttrs (oldAttrs: {
name = "docker-runc-${version}";
inherit version;
2017-04-04 14:03:55 +02:00
src = fetchFromGitHub {
owner = "opencontainers";
2017-04-04 14:03:55 +02:00
repo = "runc";
rev = runcRev;
sha256 = runcSha256;
};
# docker/runc already include these patches / are not applicable
patches = [];
});
2017-11-16 12:48:28 +01:00
docker-containerd = containerd.overrideAttrs (oldAttrs: {
name = "docker-containerd-${version}";
inherit version;
2017-04-04 14:03:55 +02:00
src = fetchFromGitHub {
owner = "containerd";
2017-04-04 14:03:55 +02:00
repo = "containerd";
rev = containerdRev;
sha256 = containerdSha256;
};
buildInputs = oldAttrs.buildInputs ++ [ libseccomp ];
2017-04-04 14:03:55 +02:00
});
2017-11-16 12:48:28 +01:00
2019-08-13 23:52:01 +02:00
docker-tini = tini.overrideAttrs (oldAttrs: {
name = "docker-init-${version}";
inherit version;
2017-04-04 14:03:55 +02:00
src = fetchFromGitHub {
owner = "krallin";
repo = "tini";
rev = tiniRev;
sha256 = tiniSha256;
};
# Do not remove static from make files as we want a static binary
patchPhase = "";
2017-04-04 14:03:55 +02:00
2019-10-30 02:29:30 +01:00
NIX_CFLAGS_COMPILE = "-DMINIMAL=ON";
2017-04-04 14:03:55 +02:00
});
moby = buildGoPackage ((optionalAttrs (stdenv.isLinux)) rec {
name = "moby-${version}";
inherit version;
inherit docker-runc docker-containerd docker-proxy docker-tini;
src = moby-src;
goPackagePath = "github.com/docker/docker";
nativeBuildInputs = [ makeWrapper pkg-config go-md2man go libtool installShellFiles ];
buildInputs = [ sqlite lvm2 btrfs-progs systemd libseccomp ];
2021-03-14 17:05:16 +01:00
extraPath = optionals (stdenv.isLinux) (makeBinPath [ iproute2 iptables e2fsprogs xz xfsprogs procps util-linux git ]);
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
'';
DOCKER_BUILDTAGS = []
++ optional (systemd != null) [ "journald" ]
++ optional (btrfs-progs == null) "exclude_graphdriver_btrfs"
++ optional (lvm2 == null) "exclude_graphdriver_devicemapper"
++ optional (libseccomp != null) "seccomp";
});
2017-11-16 12:48:28 +01:00
in
2020-07-03 09:19:24 +02:00
buildGoPackage ((optionalAttrs (stdenv.isLinux) {
2017-11-16 12:48:28 +01:00
inherit docker-runc docker-containerd docker-proxy docker-tini moby;
2017-11-16 12:48:28 +01:00
2020-07-03 09:19:24 +02:00
}) // rec {
2017-11-16 12:48:28 +01:00
inherit version rev;
name = "docker-${version}";
src = fetchFromGitHub {
owner = "docker";
repo = "cli";
2017-11-16 12:48:28 +01:00
rev = "v${version}";
sha256 = sha256;
};
2017-04-04 14:03:55 +02:00
goPackagePath = "github.com/docker/cli";
2020-07-03 09:19:24 +02:00
nativeBuildInputs = [
makeWrapper pkg-config go-md2man go libtool installShellFiles
];
buildInputs = optionals (stdenv.isLinux) [
sqlite lvm2 btrfs-progs systemd libseccomp
] ++ optionals (buildxSupport) [ docker-buildx ];
2017-04-04 14:03:55 +02:00
# Keep eyes on BUILDTIME format - https://github.com/docker/cli/blob/${version}/scripts/build/.variables
buildPhase = ''
export GOCACHE="$TMPDIR/go-cache"
cd ./go/src/${goPackagePath}
# 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}"
export BUILDTIME="1970-01-01T00:00:00Z"
source ./scripts/build/.variables
export CGO_ENABLED=1
go build -tags pkcs11 --ldflags "$LDFLAGS" github.com/docker/cli/cmd/docker
cd -
2017-04-04 14:03:55 +02:00
'';
2020-07-03 09:19:24 +02:00
postPatch = ''
patchShebangs .
substituteInPlace ./scripts/build/.variables --replace "set -eu" ""
substituteInPlace ./scripts/docs/generate-man.sh --replace "-v md2man" "-v go-md2man"
substituteInPlace ./man/md2man-all.sh --replace md2man go-md2man
'' + 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]}
2017-11-16 12:48:28 +01:00
'';
2017-04-04 14:03:55 +02:00
outputs = ["out" "man"];
installPhase = ''
2020-07-03 09:19:24 +02:00
cd ./go/src/${goPackagePath}
install -Dm755 ./docker $out/libexec/docker/docker
makeWrapper $out/libexec/docker/docker $out/bin/docker \
--prefix PATH : "$out/libexec/docker:$extraPath"
'' + optionalString (stdenv.isLinux) ''
# symlink docker daemon to docker cli derivation
ln -s ${moby}/bin/dockerd $out/bin/dockerd
2017-11-16 12:48:28 +01:00
'' + ''
# completion (cli)
installShellCompletion --bash ./contrib/completion/bash/docker
installShellCompletion --fish ./contrib/completion/fish/docker.fish
installShellCompletion --zsh ./contrib/completion/zsh/_docker
2020-07-03 09:19:24 +02:00
'' + lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
# 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-07-03 09:19:24 +02:00
'' + ''
# Generate legacy pages from markdown
echo "Generate legacy manpages"
./man/md2man-all.sh -q
2017-04-04 14:03:55 +02:00
2020-05-10 03:24:03 +02:00
installManPage man/*/*.[1-9]
2017-04-04 14:03:55 +02:00
'';
2020-11-22 01:59:08 +01:00
passthru.tests = { inherit (nixosTests) docker; };
2017-04-04 14:03:55 +02:00
meta = {
homepage = "https://www.docker.com/";
2017-04-04 14:03:55 +02:00
description = "An open source project to pack, ship and run any application as a lightweight container";
license = licenses.asl20;
2020-10-08 16:20:29 +02:00
maintainers = with maintainers; [ offline tailhook vdemeester periklis ];
platforms = with platforms; linux ++ darwin;
2017-04-04 14:03:55 +02:00
};
# Exposed for tarsum build on non-linux systems (build-support/docker/default.nix)
inherit moby-src;
2017-11-16 12:48:28 +01:00
});
2017-04-04 14:03:55 +02:00
2017-08-12 21:37:36 +02:00
# Get revisions from
# https://github.com/moby/moby/tree/${version}/hack/dockerfile/install/*
docker_20_10 = callPackage dockerGen rec {
version = "20.10.2";
2020-06-26 23:45:19 +02:00
rev = "v${version}";
sha256 = "0z0hpm5hrqh7p8my8lmiwpym2shs48my6p0zv2cc34wym0hcly51";
moby-src = fetchFromGitHub {
owner = "moby";
repo = "moby";
rev = "v${version}";
sha256 = "0c2zycpnwj4kh8m8xckv1raj3fx07q9bfaj46rr85jihm4p2dp5w";
};
runcRev = "ff819c7e9184c13b7c2607fe6c30ae19403a7aff"; # v1.0.0-rc92
runcSha256 = "0r4zbxbs03xr639r7848282j1ybhibfdhnxyap9p76j5w8ixms94";
containerdRev = "269548fa27e0089a8b8278fc4fc781d7f65a939b"; # v1.4.3
containerdSha256 = "09xvhjg5f8h90w1y94kqqnqzhbhd62dcdd9wb9sdqakisjk6zrl0";
tiniRev = "de40ad007797e0dcd8b7126f27bb87401d224240"; # v0.19.0
tiniSha256 = "1h20i3wwlbd8x4jr2gz68hgklh0lb0jj7y5xk1wvr8y58fip1rdn";
};
2014-01-24 14:39:43 +01:00
}