Adding crypttabExtraOpts to all luks devices

Hi community.

I’m on my way to learning Nix and struggling with attrsets.
I have a generic nix config file that I’m using for multiple machines but with different filesystems, luks partition structures and names. I would like to add crypttabExtraOpts to all luks devices that are defined in each system’s hardware-configuration.nix without specifying each device name.

As an example:
In machine One:
boot.initrd.luks.devices."root".crypttabExtraOpts = [ "tpm2-device=auto" ];
boot.initrd.luks.devices."rick".crypttabExtraOpts = [ "tpm2-device=auto" ];

In machine Two:
boot.initrd.luks.devices."root".crypttabExtraOpts = [ "tpm2-device=auto" ];
boot.initrd.luks.devices."morty".crypttabExtraOpts = [ "tpm2-device=auto" ];

I tried some different stuff to play around with the attrsets, but all of them ended to error: infinite recursion encountered.
I would really appreciate your time and help.

This is one of the instances I’ve tried and got error: infinite recursion encountered:

  boot.initrd.luks.devices = lib.attrsets.mapAttrs (
    dev: devAttrs: devAttrs // { crypttabExtraOpts = [ "tpm2-device=auto" ]; }
  ) config.boot.initrd.luks.devices;