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 {
    imports = [(builtins.fetchTarball {
        url = "";
        sha256 = "sha256:1ngil2shzkf61qxiqw11awyl81cr7ks2kv3r3k243zz7v2xakm5c";

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