The nerve to piriformis is a branch of the sacral plexus.
[1][2] It (typically[3]) arises from the posterior divisions[4]/branches[3] of anterior rami of S1 and S2.
[1][2][3][5] It enters the anterior surface of the piriformis muscle.
An additional branch may arise from the superior gluteal nerve.
[1] This article incorporates text in the public domain from page 957 of the 20th edition of Gray's Anatomy (1918) 홍재기