Integrating option declaration into let bending

I’ll preface with saying that keeping things very self contained appeals to me. I initially broke modules down as much as possible, ie, tty/shells/fish.nix, etc. I

I’ve recently taken the approach of defining related things within a one files let blocks, ie tty/shells.nix let fish = , etc, and merging them with a mkMerge. This has the benefit of allowing me to have a separate systemPackages for each section without having to break some things down into needlessly small files.

I’ve recently started spinning up a few servers & now need to start defining options.

I am looking for a way to integrate an option definition within the associated let binding & have been struggling to find a solution. It seems minor but the mailserver definition could otherwise include it’s own dependencies & easily be refactored by movind the block along with the mkMerge inclusion which I should be able to remove by including all let bindings under a parent binding. It does not seem that I can define an option within the let scope though … Any pointers would be appreciated. cheers.

### mailserver ============================================================================
mailserver = lib.mkIf config.services.mailserver.enable {
    imports = [(builtins.fetchTarball {
        url = "https://gitlab.com/simple-nixos-mailserver/nixos-mailserver/-/archive/nixos-23.05/nixos-mailserver-nixos-23.05.tar.gz";
        sha256 = "sha256:1ngil2shzkf61qxiqw11awyl81cr7ks2kv3r3k243zz7v2xakm5c";
      })];

    mailserver = {
      enable = true;
      fqdn = "*";
      domains = [ "*" ];
      certificateScheme = "acme-nginx";
      loginAccounts = {
        "*@*.com" = {
          hashedPasswordFile = "secrets/*";
        };
      };
    };
};
###=======================================================================================================================================================
in 
{
  options.services.mailserver.enable = lib.mkEnableOption true;
  config.os = lib.mkMerge [
    wifi ssh gnupg wireguard cloudflare 
    mailserver
  ];
}