Inconsistent ethernet device names in containers

I’m trying to set up plex in a container bridged to my LAN, but I need a consistent IP address in order to forward port 32400 through the firewall on my router. According to the docs, I can use networking.interfaces.<device-name>.macAddress, but the problem is that my containers keep getting device names like eth0@if6 and eth0@if7, seemingly according to what order they were started in, which completely defeats the purpose because now the config for eth0 is not applied (so they get assigned random MAC addresses), and my DHCP server can’t assign them consistent IP addresses from its static leases.

Is there any way to force the ethernet device name in a container so that I can set a consistent mac address?

The config I’m using to generate the plex container:

{ config, pkgs, ... }:

  hostMediaPath = "/pool/Media";
  hostDataPath = "/home/data/plex";
  guestMediaPath = "/plexmedia";
  guestDataPath = "/plexdata";
in {
  systemd.tmpfiles.rules = [
  "d ${hostDataPath} 755 karl users -"

  containers.plex = {
    autoStart = true;

    privateNetwork = true;
    hostBridge = "br0";

    bindMounts = {
      "${guestDataPath}" = {
        hostPath = "${hostDataPath}";
        isReadOnly = false;
      "${guestMediaPath}" = {
        hostPath = "${hostMediaPath}";
        isReadOnly = true;

    config = { config, pkgs, ... }: {
      boot.isContainer = true;
      networking.interfaces.eth0 = {
        useDHCP = true;
        macAddress = "52:4b:5f:9a:44:17";

      # Make sure plexuser exists (uid 1000)
      users.users.plexuser.isNormalUser = true;

      # Make sure guest path exists
      systemd.tmpfiles.rules = [
      "d ${guestDataPath} 700 plexuser users -"
      "d ${guestMediaPath} 700 plexuser users -"

      nixpkgs.config.allowUnfree = true;

      services.plex = {
        enable = true;
        openFirewall = true;
        user = "plexuser";
        dataDir = "${guestDataPath}";

I’m not sure if it’s related, but have you tried messing with enabling or disabling predictable names?

You may want to read the systemd-nspawn docs: systemd-nspawn

In theory the interface names should already be unique, I’m guessing you’re running into the collision case?

Changing the interface name by hand is not possible in the systemd-nspawn world, according to the documentation, but you can create arbitrarily-named additional veths.