So, I was able to reproduce this with Nix 2.18.5, but not the latest 2.18.x which is 2.18.9. So whatever the bug is, it was fixed by then.
@eureka-cpu Reported something similar, and in the revision of nixpkgs they said they were using before, Nix 2.18.5 was the default Nix version. So presumably that’s why they were affected. (Sidenote, that nixpkgs version is from july, so it must have been a while since you updated!)
Nonetheless, clearly nixpkgs has recently made a change triggering this bug. So I decided to bisect nixpkgs, and found that this was the culprit: make-initrd: use closureInfo again by xaverdh · Pull Request #372931 · NixOS/nixpkgs · GitHub
So there must have been some bug with exportReferencesGraph
that was fixed before 2.18.9. I’ve also tested it with Nix 2.3 (which is currently the oldest version of Nix that NixOS is required to remain compatible with) and it does not seem to exhibit the bug. So I don’t think that PR needs to be reverted. I think users simply need to be advised not to use obsolete versions of Nix, e.g. 2.18.5 when 2.18.9 exists.