{
  config,
  lib,
  ...
}:
let
  cfg = config.khscodes.networking;
in
{
  options.khscodes.networking = {
    fqdn = lib.mkOption {
      type = lib.types.str;
      default = null;
      description = "Sets the FQDN of the machine. This is a prerequisite for many modules to be used";
    };
    aliases = lib.mkOption {
      type = lib.types.listOf lib.types.str;
      default = [ ];
    };
  };

  config =
    let
      hostname = builtins.head (lib.strings.splitString "." cfg.fqdn);
      domain = if hostname == cfg then null else (lib.strings.removePrefix "${hostname}." cfg.fqdn);
    in
    {
      networking.hostName = lib.mkForce hostname;
      networking.domain = lib.mkForce domain;
      networking.fqdn = cfg.fqdn;
      # Add the name of the server to the ssh host certificate domains, but let other configs enable getting the host certificates.
      khscodes.services.openssh.hostCertificate.hostNames = lib.lists.unique (
        [ cfg.fqdn ] ++ cfg.aliases
      );
      boot.kernel.sysctl = {
        "kernel.hostname" = cfg.fqdn;
      };
    };
}
