Macvlan network devices not being properly cleaned up?

I’m running into a couple different problems that seem like they might be related, all involving macvlan network interfaces.

First, I’m running a couple NixOS containers to which I want to assign separate IPs, so I’ve been creating macvlans for them to use (via containers.macvlans), and then configuring the network within the container. This works well, and the container can listen on the new IP without interfering with the parent host. However, whenever I rebuild the OS on the parent host (pushed using NixOps), the container can no longer assign the IP address to the macvlan interface with the error: “RTNETLINK answers: Address already in use”.

I don’t see the address in ip addr in the container, or on the parent host. I’m not able to ping it or anything. Restarting the container doesn’t help. So far, the only way I’ve found to fix it is to restart the parent host itself.

I’ve also got a couple hosts that use a macvlan as their primary interface (no container involved). A couple of them have fixed IP addresses which I configure manually; the others are using DHCP. When I push a new build to them, the static-IP hosts come back just fine, but the dynamic ones occasionally disappear. It’s got something to do with the build (they all succeed or fail together), and it’s been happening over a couple years. It seems like changes affecting networking (and requiring a restart of network services) cause DHCP to fail. Meanwhile, hosts that do not use a macvlan work fine.

Does anybody know what I’m doing wrong, or what the problem might be? In the first case, where is that IP assigned? I don’t see any interfaces or aliases anywhere. Is there a way to find and unassign it?

Edit: Out of curiosity, I tried a restart (instead of upgrade) on the container from the first example. That worked just fine!