I was toying with the idea of reintroducing an equivalent to the old iptables specific extra option which allowed passing arbitrarily iptables arguments. We could introduce a new option nft … which is valid in all section types and then allow configuring it through uci.
Problem is that such an option is a loaded shotgun aimed at your feet… it is impossible to validate ui-side and entering something invalid will render the whole firewall inoperable since the ruleset cannot be loaded.
Likely, just need to see how much surrounding context is needed and how to do it in the most efficient way. You probably need to embed the rule plus custom expressions into a chain structure resembling the final ruleset structure before validating it. Custom expressions could also reference named sets and the like, so need to see
In case of any use at all, in cake-qos-simple it seemed to work nicely to create a custom nft file on the fly based on customisable variables with own table like so: