Nails are a much older "invention of evolution" than humans: so we have to investigate there...
> how do nails and hairs manage to grow only in one direction
Like all things evolution: nails that grow backwards to not have an advantage (prolly a disadvantage), where nails that grow forwards have an advantage (climbing, clawing, scratching).