# ~/.ssh/config
{
  systemConfig,
  systems,
  common,
  ...
}:
with builtins;

{
  programs.ssh = {
    enable = true;
    matchBlocks = listToAttrs (
      map (system: {
        name = system.hostName;
        value =
          let
            hostName =
              if (system ? address && system.address ? tailnet) then
                system.address.tailnet
              else
                common.tailnetAddr system.hostName;
          in
          {
            port = 22;
            user = systemConfig.username;
            hostname = hostName;
          };
      }) systems
    );
  };
}
