Nixos Container multiple IP addresses

Hello,

I’m running Kafka inside a nixos-container defined in a flake.
Everything works fine except for the fact that when create the container it gets 2 IPv4 addresses assigned and only one of them works.

Because of that when I try to reach Kafka from my host it fails randomly depending on which IP address it tries.

Is there a way to force it to only get one IP address assigned?


This is the flake configuration for the container:

{
  description = "Kafka service container for local testing";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11";
  };

  outputs = { nixpkgs, flake-utils, ... }: {
    nixosConfigurations = {
      kafka = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ({ pkgs, ... }: {
            boot.isContainer = true; # Only boot as container
            system.stateVersion = "22.11";
            environment.systemPackages = [
              pkgs.kcat
            ];

            networking = {
              hostName = "kafka";
              enableIPv6 = false;
              firewall.allowedTCPPorts = [ 9092 ];
            };

            services = {
              apache-kafka.enable = true;
              zookeeper.enable = true;
            };
          })
        ];
      };
    };
  };
}

and this is how I create and start it as well as the machinectl status output

Here I would like to only have the IP address 10.233.1.2

The IP address 169.254.49.202 is part of the Automatic Private IP Addressing (APIPA) range, which is reserved for use by hosts that cannot obtain an IP address from a DHCP server. It’s usually set by a DHCP client.

How does it get the other IP 10.233.1.2?