Yes, it's legal, but discouraged. Please see RFC 9229 Section 2.1:
Thanks Juliusz, for confirming and for making the allowance in the
RFC in the first place.
Attached is a patch that optionally allows extended next hop to be
set for IPv4 routes. Please take a look.