Here's probably the most idiomatic Nix code for what you're asking. Noogle is your friend for finding library functions.
{
rightModules = [
"group/expand"
"wireplumber"
"network"
"privacy"
]
++ lib.optional components.bluetooth "bluetooth"
++ lib.optional components.battery "battery"
++ [
"custom/wlogout"
];
}