How can I create a directory and setgid?

As the title says, I want to—from my configuration.nix—create a directory, then setgid on it so that any files created within take the group’s ownership. How can I do this?

I currently have the following to create the directory, though I don’t know if it’s the best way to do so and can’t figure out how to then setgid.

systemd.tmpfiles.rules = [
"d dir/path 770 user group"

The 8^3 octal place value controls the setuid, setgid, and sticky bits, so I believe a mode of 2770 in the tmpfiles rule should do the trick.

Also, yes. Outside of /etc, a tmpfiles rule is generally the way to do this.

Excellent thank you.