Cannot build docker image on macOS aarch64

I want to build a docker image using dockerTools. While this worked perfectly fine on Linux, I get the following error on macOS aarch64:

json_t** stack_safe_peek()
                        ^
                         void
jshon.c:222:23: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
mapping* map_safe_peek()
                      ^
                       void
jshon.c:229:13: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void MAPPUSH()
            ^
             void
jshon.c:251:13: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void MAPNEXT()
            ^
             void
jshon.c:276:12: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void MAPPOP()
           ^
            void
jshon.c:846:15: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void debug_map()
              ^
               void
6 errors generated.
make: *** [<builtin>: jshon.o] Error 1

the flake im using is

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    rust-overlay.url = "github:oxalica/rust-overlay";
  };
  outputs = { self, nixpkgs, rust-overlay, ... }:
      let
        overlays = [ (import rust-overlay) ];
        system = "aarch64-darwin";
        pkgs = import nixpkgs { inherit system overlays; };

        # rust-bin is overwritten in rust-overlay
        rustVersion = pkgs.rust-bin.stable.latest.default;

        # makeRustPlatform is defined in rust-overlay
        rustPlatform = pkgs.makeRustPlatform { 
          cargo = rustVersion;
          rustc = rustVersion;
        };
        myRustBuild = rustPlatform.buildRustPackage {
          pname = "nix-rust-build"; # project name
          version = "0.1.0";
          src = ./.; 
          cargoLock.lockFile = ./Cargo.lock;
        };

        dockerImage = pkgs.dockerTools.buildImage {
          name = "nix-rust-build-container";
          tag = "latest";
          copyToRoot = [ myRustBuild ];
          config = { Cmd = [ "/bin/nix-rust-build" ]; };
        };

      in {
        packages."aarch64-darwin".rustPackage = myRustBuild;
        packages."aarch64-darwin".image = dockerImage;
        packages."aarch64-darwin".default = dockerImage;
      };
}

I understand the problem (the C error) and would be willing to fix it and create a PR to jshon if this is the way to go. Nevertheless I would appreciate if there would be another solution.

You can’t.

dockerTools simply do not work on *-darwin.

If you want to build your docker images on a Mac, you have to wrap that build in a Linux VM or a docker container (which also effectively runs in a VM on MacOS).

There might be ways using actual cross compilation, though I doubt figuring the details are not worth the effort.