Same path for go binary in multi arch docker image

I’m trying to add arm64/aarch64 support to an image build with nix. The main component is written in go and uses buildGoModule. I think I managed to do that – I am building two images, one with amd64 and one with aarch64 architecture. However, the symlink to the binary that is the entrypoint in the docker image has changed. It used to be at /bin/<name> but is now at /bin/linux_amd64/<name>. I’m unable to figure out how to change that.

What I did was to duplicate most things and call it with a different architecture parameter:

  outputs = { self, nixpkgs, flake-utils}:
    flake-utils.lib.eachDefaultSystem (system:
        pkgs = nixpkgs.legacyPackages.${system};
        containerPkgsAmd64 = import nixpkgs { localSystem = system; crossSystem = "x86_64-linux"; };
        containerPkgsAArch64 = import nixpkgs { localSystem = system; crossSystem = "aarch64-linux"; };
        goModuleAmd64 = import ./devenv/nix/goModule.nix { inherit pkgs; architecture = "amd64";};
        csiDriverAmd64 = goModuleAmd64.csiDriver;
        csiDriverLinuxAmd64 = goModuleAmd64.csiDriverLinux;

        goModuleAarch64 = import ./devenv/nix/goModule.nix { inherit pkgs; architecture = "arm64";};
        csiDriverAarch64 = goModuleAarch64.csiDriver;
        csiDriverLinuxAarch64 = goModuleAarch64.csiDriverLinux;

        dockerLayerdImageAmd64 = import ./devenv/nix/containerImage.nix {
            inherit pkgs;
            csiDriverLinux = csiDriverLinuxAmd64;
            containerPkgs = containerPkgsAmd64;
            architecture = "amd64";
        dockerLayerdImageAArch64 = import ./devenv/nix/containerImage.nix {
            inherit pkgs;
            csiDriverLinux = csiDriverLinuxAarch64;
            containerPkgs = containerPkgsAArch64;
            architecture = "aarch64";

and in the buildGoModule I’ve added the parameters for cross compilation like this

csiDriverLinux = csiDriver.overrideAttrs (old: old // { CGO_ENABLED = 0; GOOS = "linux"; GOARCH=architecture; });

and containerImage uses streamLayeredImage like this:

pkgs.dockerTools.streamLayeredImage {
  name = "csi-rclone";
  tag = "latest";
  architecture = architecture;

  contents = [

    # others

I don’t know if that’s idiomatic for nix (it’s my first contact), but the results look good, except for the diverging paths. Ideally both images have the same structure, so they can be used identically on their respective architecture.

I’ve tried to create an additional symlink as extraCommands in streamLayeredImage, but that yields a Operation not permitted.