Nix-collect-garbage error because "File name too long"

I was messing around with out of store symlinks without really knowing what I was doing, and ended up creating a file in the nix store which is “/nix/store/hash/myfolder/store/hash/myfolder/store/hash/myfolder/…” repeated multiple times. Nix-collect-garbage fails to remove it due to the long file name.

The solution is to sudo mount -o remount,rw /nix/store, deleting the offending folder with rm -rf, then sudo mount -o remount,ro /nix/store.

I couldn’t find any mention of the problem on Google, the solution was kindly provided by K900 on Matrix.