Uefi on flashdisk

I want install nixos on flashdisk but i confuse how to config the grub.
I have 2 computer, 1 computer only support legacy boot, 1 computer only support uefi.
I want my nixos on flashdisk can boot on 2 device i mentioned on above.
Can you give me example how to config the grub?