{ config, pkgs, lib, ... }:

{
  imports =
    [
      ./hardware-configuration.nix
      ../../configuration/router
    ];

  profiles.clerie.hetzner-cloud.enable = true;

  boot.loader.grub.enable = true;
  boot.loader.grub.device = "/dev/sda";

  networking.useDHCP = false;
  systemd.network.enable = true;

  systemd.network.networks."10-wan" = {
    address = [
      "2a01:4f8:c0c:15f1::1/64"
      "78.47.183.82/32"
    ];
  };

  networking.nat = {
    enable = true;
    externalInterface = "ens3";
    internalInterfaces = [ "wg-vpn" ];
    internalIPs = [ "10.20.30.0/24" ];
  };

  networking.wireguard.enable = true;
  networking.wireguard.interfaces = {
    wg-vpn = {
      ips = [ "2a01:4f8:c0c:15f1::8001/113" "10.20.30.1/24" ];
      peers = [
        {
          # krypton
          allowedIPs = [ "2a01:4f8:c0c:15f1::8011/128" "10.20.30.11/32" ];
          publicKey = "NA/vdmoKQ5bpPKKrRPUpI17bNPoviRXnZ61iV4Q1VUQ=";
        }
        {
          # krypton full
          allowedIPs = [ "2a01:4f8:c0c:15f1::8111/128" "10.20.30.111/32" ];
          publicKey = "QGQHWwDE1XIeiReFcacLxin4Dqlz1pBXvttFnzBMJSY=";
        }
        {
          # ceasium
          allowedIPs = [ "2a01:4f8:c0c:15f1::8012/128" "10.20.30.12/32" ];
          publicKey = "tvWpYlaS3ItTWH9CZv4SHzXToIblJP2j+Mt1V+3cegM=";
        }
        {
          # terra
          allowedIPs = [ "2a01:4f8:c0c:15f1::8014/128" "10.20.30.14/32" ];
          publicKey = "peZ94x44sMRNqNxcaN+DI2UMwVFzugZjnnbqbxWcBEs=";
        }
        {
          # e1mo
          allowedIPs = [ "2a01:4f8:c0c:15f1::8015/128" "10.20.30.15/32" ];
          publicKey = "j+ao/TTTE2hThdqBtLQuC67QSaKXMhhWTky6MzkhrxY=";
        }
        {
          # jannik
          allowedIPs = [ "2a01:4f8:c0c:15f1::8016/128" "10.20.30.16/32" ];
          publicKey = "V6Kc++QmJ4RkLSWvcLj/KgbIafvi7URV6dOgFnKSAwM=";
        }
        {
          # evey
          allowedIPs = [ "2a01:4f8:c0c:15f1::8017/128" "10.20.30.17/32" ];
          publicKey = "DD18B0plaYuhHK+yJ1nlEv6EmM+Krw/alXmz+X3SI18=";
        }
        {
          # amy
          allowedIPs = [ "2a01:4f8:c0c:15f1::8018/128" "10.20.30.18/32" ];
          publicKey = "tXO6qzYGTcuiMZhfTF2Af1qoIdpv3EqqepldrjVm9hI=";
        }
        {
          # palladium
          allowedIPs = [ "2a01:4f8:c0c:15f1::8103/128" "10.20.30.103/32" ];
          publicKey = "kxn69ynVyPJeShsAlVz5Xnd7U74GmCAw181b0+/qj3k=";
        }
        #{
        #  allowedIPs = [ "2a01:4f8:c0c:15f1::8104/128" "10.20.30.104/32" ];
        #  publicKey = "k1eQINwZPRdIEhND5sKAcHMxEpz/Z+B/2ZCdLhHCG3w=";
        #}
        {
          # vcp-bula-mon
          allowedIPs = [ "2a01:4f8:c0c:15f1::8105/128" "10.20.30.105/32" ];
          publicKey = "6gi04ExLQnpwxmTzQwQz3AsPS+ujKmANh6+o0nAzJwM=";
        }
        {
          # aluminium
          allowedIPs = [ "2a01:4f8:c0c:15f1::8106/128" "10.20.30.106/32" ];
          publicKey = "kuUeStBuU6d8PGFHFhP5pEvy0nuZ0TmScI8w7MOt0is=";
        }
        {
          # beryllium
          allowedIPs = [ "2a01:4f8:c0c:15f1::8107/128" "10.20.30.107/32" ];
          publicKey = "SReFUcvw/4fLSkFGjkhDRyY9wyMCcjJ4Yiczt9X64Eo=";
        }
        {
          # astatine
          allowedIPs = [ "2a01:4f8:c0c:15f1::8108/128" "10.20.30.108/32" ];
          publicKey = "4b4M+we+476AV/fQ3lOmDbHFA0vvb3LwOEPVvNpuGm0=";
        }
        {
          # zinc
          allowedIPs = [ "2a01:4f8:c0c:15f1::8109/128" "10.20.30.109/32" ];
          publicKey = "syHX6PO1N3Annv5t2W8bdAo/kMoYenzrcPrUHxkIBEE=";
        }
        {
          # zinc-initrd
          allowedIPs = [ "2a01:4f8:c0c:15f1::8110/128" "10.20.30.110/32" ];
          publicKey = "kn6ZtViagKGSyfQJQW6csQE/5r7uKlbC1rbInlQ33xs=";
        }
        {
          # carbon
          allowedIPs = [ "2a01:4f8:c0c:15f1::8111/128" "10.20.30.111/32" ];
          publicKey = "o6qxGKIoW2ZSFhXeNRXd4G9BRFeYyjZsrUPulB3KhTI=";
        }
        {
          # tungsten
          allowedIPs = [ "2a01:4f8:c0c:15f1::8112/128" "10.20.30.112/32" ];
          publicKey = "OI5/psr3ShrwRqKTTr3Kv92OVRietTcMFNVXtsYybRo=";
        }
      ];
      listenPort = 51820;
      allowedIPsAsRoutes = false;
      privateKeyFile = config.sops.secrets.wg-vpn.path;
    };
  };

  networking.firewall.allowedUDPPorts = [ 51820 ];

  clerie.nginx-port-forward = {
    enable = true;
    tcpPorts."443" = {
      host = "localhost";
      port = 22;
    };
    tcpPorts."2022" = {
      host = "nonat.net.clerie.de";
      port = 22;
    };
  };

  clerie.monitoring = {
    enable = true;
    id = "101";
    pubkey = "H9Pvx/BzwEMM7acT9mioT8zBD2Yn13L82EKKqdAfeGM=";
    blackbox = true;
  };

  system.stateVersion = "21.03";
}