dockerTools.buildLayeredImage fails where buildImage succeeds

I am trying to build multiarch OCI images on a macOS host. The following code works:

      mkDockerImage = pkgs: targetSystem:
        let
          archSuffix = if targetSystem == "x86_64-linux" then "amd64" else "arm64";
          my-golang-package = pkgs.callPackage ./package.nix { };
        in
        pkgs.dockerTools.buildImage {
          name = "my-oci-image";
          tag = "${imageTag}-${archSuffix}";
          copyToRoot = pkgs.buildEnv {
            name = "image-root";
            paths = [ my-golang-package ];
          };
          config = {
            EntryPoint = [ "${my-golang-package}/bin/webserver" ];
            Labels = lib.mapAttrs'(k: v: {name= "org.opencontainers.image." + k; value=v;}) {
              licenses = with lib; licenses.unfree.fullName;
              revision = "${my-golang-package.version}";
              version = "${my-golang-package.version}";
            };
          };
        };

but as soon as I switch the following lines I get an error from fakeroot:

pkgs.dockerTools.buildLayeredImage {
  name = "my-oci-image";
  tag = "${imageTag}-${archSuffix}";
  contents = pkgs.buildEnv {
    name = "image-root";
    paths = [ my-golang-package ];
  };
  ...
};

error:

>: nix log /nix/store/7yipzxjk2g9lsibvlhcmjqbvwjwpqzcx-my-oci-image-customisation-layer.drv
dyld[2720]: symbol not found in flat namespace '_fstat$INODE64'
/nix/store/yymj6xxs57aa9kik39b7nihkj2zvfkm7-fakeroot-1.36/bin/fakeroot: line 178:  2720 Abort trap: 6    >
lines 1-2/2 (END)

If this is a linking problem, why does it only happen when I try to use streamLayeredImage or buildLayeredImage? I am building my-golang-package using buildGoModule, I can share that too, if needed.

Another thought popped into my head. dyld is the dynamic linker of macOS (which, unlike linux does not have a stable syscall API). But I am cross-compiling to aarch64-linux and trying to build a statically linked image, not linked against macOS libsystem.

I’ve just run into this same issue. I’m also on macOS. I’m building an image with a python venv, using remote builders to get linux binaries. Still investigating…