Sexually dimorphic traits in morphologies are widely studied,1,2,3,4 but those in essential molecular pathways remain largely unexplored. Previous work showed substantial sex differences in Drosophila gonadal piRNAs,5 which guide PIWI proteins to silence selfish genetic elements, thereby safeguarding fertility.6,7,8 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 germ line rather than the gonadal somatic cells. Building on this, we dissected the contribution of sex chromosomes and cellular sexual identity toward 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 chromosomes and sexual identity collectively sculpt an essential molecular trait.