Sexually dimorphic traits in morphologies are widely studied, but those in essential molecular pathways remain largely unexplored. Previous work showed substantial sex differences in Drosophila gonadal piRNAs, which guide PIWI proteins to silence selfish genetic elements thereby safeguarding fertility. However, the genetic control mechanisms of piRNA sexual dimorphism remain unknown. Here, we showed that most sex differences in the piRNA program originate from the germline rather than gonadal somatic cells. Building on this, we dissected the contribution of sex chromosome and cellular sexual identity towards the sex-specific germline piRNA program. We found that the presence of the Y chromosome is sufficient to recapitulate some aspects of the male piRNA program in a female cellular environment. Meanwhile, sexual identity controls the sexually divergent piRNA production from X-linked and autosomal loci, revealing a crucial input from sex determination into piRNA biogenesis. Sexual identity regulates piRNA biogenesis through Sxl and this effect is mediated in part through chromatin proteins Phf7 and Kipferl. Together, our work delineated the genetic control of a sex-specific piRNA program, where sex chromosome and sexual identity collectively sculpt an essential molecular trait.