{
  config,
  lib,
  pkgs,
  system,
  ...
}:
let
  cfg = config.khscodes.hetzner;
in
{
  options.khscodes.hetzner = {
    enable = lib.mkEnableOption "Enables the machine as a hetzner machine";
    diskName = lib.mkOption {
      type = lib.types.str;
      default = "nixos";
      description = "Name of the root disk device";
    };
    metadataApiUri = lib.mkOption {
      type = lib.types.nullOr lib.types.str;
      default = null;
      description = "Sets the metadata API url that the server will contact to gather metadata information from. Should probably only be used for testing";
    };
  };

  config = lib.mkIf cfg.enable {
    disko = lib.khscodes.disko-root-lvm-uefi {
      device = "/dev/sda";
      diskName = cfg.diskName;
    };

    boot.tmp.cleanOnBoot = lib.mkDefault true;
    boot.initrd.kernelModules = lib.mkIf (system == "aarch64-linux") [ "virtio_gpu" ];
    boot.kernelParams = lib.mkIf (system == "aarch64-linux") [ "console=tty" ];
    zramSwap.enable = lib.mkDefault true;
    khscodes.systemd-boot.enable = lib.mkDefault true;
    khscodes.virtualisation.qemu-guest.enable = true;
    networking = {
      useDHCP = false;
      useNetworkd = false;
    };
    systemd.network = {
      enable = true;
      networks."10-enp1s0" = {
        matchConfig.Name = [
          "eth0"
          "enp1s0"
        ];
        networkConfig = {
          DHCP = "ipv4";
        };
        linkConfig.RequiredForOnline = "routable";
      };
    };

    systemd.services.hetzner-static-ip = {
      enable = true;
      wants = [ "network-online.target" ];
      after = [ "network-online.target" ];
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        Type = "oneshot";
        RemainAfterExit = true;
        ExecStart = ''
          ${lib.getExe pkgs.khscodes.hetzner-static-ip} configure
        '';
      };
      environment =
        {
          PATH = lib.mkForce "";
        }
        // lib.attrsets.optionalAttrs (cfg.metadataApiUri != null) {
          INSTANCE_API_URI = cfg.metadataApiUri;
        };
    };
  };
}
