This is a topic that has come up before (and issue #39069) and generated multiple PRs (#39329, #47664); I’d like to try and understand the current situation and how to achieve the stated goal in the title at present, and hopefully even help get any remaining issues with this fixed upstream.
To avoid any confusion, the desired end goal is that I want my Ethernet device to be
enp4s0 even in the initrd network (which uses dropbear to receive a disk encryption password over SSH), not to have
eth0 consistently (which can be achieved by setting the NixOS
networking.usePredictableInterfaceNames option, if it works (I think
net.ifnames=0 is still supported), or else by setting the
net.naming-scheme=... kernel command-line parameter (sources:
Previously, I was using the workaround described in the previous Discourse thread and enhanced in the latter PR successfully. Unfortunately, it doesn’t seem to be working any more; as I described in this comment, the
80-net-setup-link.rules file that this technique uses has been removed from NixOS as of commit
1f03f6f. Apparently, udev now does the renaming itself in C code, and therefore the
.rules file is no longer required. But unfortunately, the initrd network does not seem to behave correctly in practice – NixOS stage2 starts with
eth0 and fails to rename it due to the device being busy.
Hopefully someone is able to help shed any light on this confusing issue or even just offer a working workaround.