Nixos container does not get dhcp ipv4 address upon host reboot

I have a Nixos container setup that just servers a web directory on port 80. The container is setup to use the bridge br0 on the host. When I reboot the host, the container starts, but it doesn’t get an ipv4 address. If I stop and start the container, it gets the ipv4 address. I am thinking its something to do with the timing of network interfaces being setup and containers being started but that is a guess and I am unsure how to proceed.

Host network configuration:

  networking.networkmanager.enable = true;
  networking.useDHCP = false;
  networking.bridges = {
    "br0" = {
      interfaces = [ "enp3s0f2" ];
    };
  };
  networking.interfaces.br0.ipv4.addresses = [ {
    address = "192.168.1.10";
    prefixLength = 24;
  } ];
  networking.defaultGateway = "192.168.1.1";
  networking.nameservers = ["8.8.8.8" "8.8.4.4"];
  networking.firewall.trustedInterfaces = [ "br0" ];

Container config

  containers.media-share = {
    autoStart = true;
    privateNetwork = true;
    hostBridge = "br0";
    bindMounts = {
      "/var/www/media-share.lan/media" = {
        hostPath = "/mnt/6tb/media";
        isReadOnly = true;
      };
    };
    config = { config, pkgs, ... }: {
      system.stateVersion = "23.05";
      networking.networkmanager.enable = true;
      networking.hostName = "media-share";
      networking.firewall.enable = false;
      services.httpd.enable = true;
      services.httpd.virtualHosts."media-share.lan" = {
        documentRoot = "/var/www/media-share.lan";
      };
    };
  };

good news, i had this problem, bad news i can’t remember how i fixed it, this is a note to me to blog about things when i fix them.

The words vxlan, taptun are in my brain pan… if i get more recall, i’ll update you.

1 Like