{
  config,
  lib,
  namespace,
  ...
}:
with lib;
let
  name = "headscale";
  cfg = config.${namespace}.services.${name};

  headscaleConfig = lib.${namespace}.mkModule {
    inherit config name;
    description = "headscale";
    options = { };
    moduleConfig = {
      services.headscale = {
        enable = true;
        address = cfg.listenAddress;
        port = cfg.port;
        settings = {
          server_url = "https://headscale.mjallen.dev:443";
          database.sqlite.path = "${cfg.configDir}/headscale/db.sqlite";
          dns = {
            nameservers.global = [
              "1.1.1.1"
              "8.8.8.8"
            ];
            base_domain = "tailnet.mjallen.dev";
            magic_dns = true;
          };
        };
        # oidc
      };
    };
  };
in
{
  imports = [ headscaleConfig ];
}
