From 5dde5ea73e532d8dcfb134abc8d98d0f47813cde Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Wed, 4 Aug 2021 09:52:49 +1000 Subject: [PATCH] tarsum: init - move from dockerTools.tarsum - remove go from runtime closure --- pkgs/build-support/docker/default.nix | 21 ++------------ pkgs/build-support/docker/tarsum.nix | 42 +++++++++++++++++++++++++++ pkgs/top-level/all-packages.nix | 1 + 3 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 pkgs/build-support/docker/tarsum.nix diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index 4bda09670ab..86422a760bf 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -5,7 +5,6 @@ callPackage, closureInfo, coreutils, - docker, e2fsprogs, fakeroot, findutils, @@ -17,6 +16,7 @@ moreutils, nix, pigz, + pkgs, rsync, runCommand, runtimeShell, @@ -123,24 +123,7 @@ rec { # We need to sum layer.tar, not a directory, hence tarsum instead of nix-hash. # And we cannot untar it, because then we cannot preserve permissions etc. - tarsum = runCommand "tarsum" { - nativeBuildInputs = [ go ]; - } '' - mkdir tarsum - cd tarsum - - cp ${./tarsum.go} tarsum.go - export GOPATH=$(pwd) - export GOCACHE="$TMPDIR/go-cache" - export GO111MODULE=off - mkdir -p src/github.com/docker/docker/pkg - ln -sT ${docker.moby-src}/pkg/tarsum src/github.com/docker/docker/pkg/tarsum - go build - - mkdir -p $out/bin - - cp tarsum $out/bin/ - ''; + tarsum = pkgs.tarsum; # buildEnv creates symlinks to dirs, which is hard to edit inside the overlay VM mergeDrvs = { diff --git a/pkgs/build-support/docker/tarsum.nix b/pkgs/build-support/docker/tarsum.nix new file mode 100644 index 00000000000..734c6b3d5ae --- /dev/null +++ b/pkgs/build-support/docker/tarsum.nix @@ -0,0 +1,42 @@ +{ stdenv, go, docker, nixosTests }: + +stdenv.mkDerivation { + name = "tarsum"; + + nativeBuildInputs = [ go ]; + disallowedReferences = [ go ]; + + dontUnpack = true; + + CGO_ENABLED = 0; + GOFLAGS = "-trimpath"; + GO111MODULE = "off"; + + buildPhase = '' + runHook preBuild + mkdir tarsum + cd tarsum + cp ${./tarsum.go} tarsum.go + export GOPATH=$(pwd) + export GOCACHE="$TMPDIR/go-cache" + mkdir -p src/github.com/docker/docker/pkg + ln -sT ${docker.moby-src}/pkg/tarsum src/github.com/docker/docker/pkg/tarsum + go build + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out/bin + cp tarsum $out/bin/ + runHook postInstall + ''; + + passthru = { + tests = { + dockerTools = nixosTests.docker-tools; + }; + }; + + meta.platforms = go.meta.platforms; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 412985e644a..31e7e1cf117 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -369,6 +369,7 @@ in dockerTools = callPackage ../build-support/docker { writePython3 = buildPackages.writers.writePython3; }; + tarsum = callPackage ../build-support/docker/tarsum.nix { }; snapTools = callPackage ../build-support/snap { };