Rhys Darby is set for the lead role in the upcoming HBO Max pirate comedy series “Our Flag Means Death,” Variety has learned.

The series was originally ordered at the streamer back in September. It is loosely based on the real life of Stede Bonnet (Darby), a well-to-do gentleman farmer and child of wealth in the 18th century who suffers a mid-life crisis and becomes captain of the pirate ship “The Revenge.”

The role will reunite Darby with Taika Waititi, who is attached to executive produce and direct the pilot of the series. The pair previously worked together on the HBO series “Flight of the Conchords” and the film “What We Do in the Shadows.” Darby starred in both projects, with Waititi serving as a writer and director on the HBO series and star, co-writer, co-director, and producer on the film. Darby is also set to appear in the upcoming sports comedy “Next Goal Wins,” which Waititi is co-writing and directing.

Darby’s other roles include films like the rebooted “Jumanji” franchise, “Guns Akimbo,” and “Yes Man.” On the TV side, he previously starred in the TBS comedy “Wrecked” and has appeared on shows like “The X-Files,” “Angie Tribeca,” “Fresh Off the Boat,” “Life in Pieces,” “Bob’s Burgers,” and “Rise of the Teenage Mutant Ninja Turtles.”

He is repped by UTA, Artists First, and Morris Yorn.

“Our Flag Means Death” hails from writer, showrunner, and executive producer David Jenkins. Garrett Basch and Dan Halsted also serves as executive producers. The current plan is to shoot the first episode once Waititi wraps production on the Marvel film “Thor: Love and Thunder.”