Yes it's safe for dogs to eat dirt.
Dogs usually eat dirt because of anemia or rare iron or mineral deficiencies.
Sometimes it's just the dog being bored and wanting to eat the dirt and it's not harmful to the dog unless the dog happened to eat a large enough rock to cause choking.
Even kids eat dirt sometimes as toddlers and I remember when I was 3 and 4 years old that I would go outside and eat dirt with a spoon.
I once got a rock in my mouth at age 3 and my mom had to get it out of my mouth but I was okay and yes I did swallow the dirt I ate but not the rocks.
So just like humans who eat dirt as kids and toddlers a dog eating dirt will do them no harm either.