Kaguya developed the eye after she ate the fruit. Nothing suggests otherwise, as the flower of the tree seems to have it. Though I have seen that its Tomoes are inconsistent and has shown 6, like Sasuke's most of the time. Kaguya's eye has been called Sharingan and Rinnegan in the manga. So, it's technically both.So Kaguya got it cuz she is "Godess itself" ?
Madara cuz he got Rinnegan Plus Juubi Power Plus Hashirama Cells ?
And Sasuke awakend Rinnegan when he was almost dead and got his tomoes when he gained yin or Yang Chikara from Hagoromo ?
Madara awoke it after absorbing the tree as well. That much is a fact. Whether he even had it before it or not is a moot point.
Sasuke's eye is similar to the original Sharingan, but without one ring of Tomoes and has a distinct colour. It seems to be something unique to him, so, I guess it has something to do with Hogoromo's chakra alone. Kishimoto never bothered explaining it, so, this is the best I can do.