How to add optional listitem

Hello

I’ll try to explain with an example, because I might not know all the nomenclature.

startup = [
  { command = "${cmd1}"; always = true; } # In all configurations
  { command = "${cmd2}"; always = true; } # Only when certain conditions are met
];
options.cfg.graphical.sway.command-2 = lib.mkOption {
  default = false;
  example = true;
};

cmd1 should always be in the startup list.
cmd2 should only be in the startup list when enabled:

cfg.graphical.sway.command-2 = true;

I’ve seen

config = lib.mkIf config.cfg.graphical.enable {};

before but I don’t know if this is useful for a list.
Or if this can be used when a part is always needed and some other part only when certain conditions are met.

Thanks for reading.

startup = [
  { command = "${cmd1}"; always = true; } # In all configurations
] ++ lib.optionals config.chvp.graphical.sway.command-2 [
  { command = "${cmd2}"; always = true; } # Only when certain conditions are met
];