{ lib, pkgs, config, inputs, ... }: let
  flakePackage = flake: inputs.${flake}.packages.${pkgs.system}.default;
in rec {
  imports = [
    ../../templates/proxmox-lxc.nix
    ../../server.nix
    ../../features/dns-cache.nix
    ../../features/nginx.nix
    ../../features/telemetry/nginx.nix
  ];

  networking.hostName = "static-sites";
  system.stateVersion = "24.05"; 
  nixpkgs.hostPlatform = "x86_64-linux";
  
  networking.firewall.allowedTCPPorts = [ 80 ];
  networking.firewall.allowedUDPPorts = [ 80 ];

  services.nginx = {
    recommendedBrotliSettings = true;
    recommendedGzipSettings = true;
    recommendedZstdSettings = true;    

    virtualHosts = let
      defaultConfig = {
        listen = [
          { addr = "0.0.0.0"; port = 80; }
          { addr = "[::]"; port = 80; }
        ];    
      };
      static = { src ? null, url ? null, rev ? null, aliases ? [] }: {
        serverAliases = aliases;

        root = if src != null then src else builtins.fetchGit { inherit url rev; };
      } // defaultConfig;
      placeholder = {
        locations."=/" = {
          root = pkgs.writeText "placeholder.html" "empty space -- this site is non-functional";
          extraConfig = ''
            default_type text/plain;
          '';
        };
      } // defaultConfig;
    in rec {
      "noe.sh" = static { src = flakePackage "noe-sh"; aliases = [ "mekanoe.com" ]; } // {
        locations."=/" = {
          extraConfig = ''
            if ($http_user_agent ~ curl/) {
              rewrite ^ /noe.sh;
            }
          '';
        };
      };
      # "3d.noe.sh" = static { src = flakePackage "3d-noe-sh"; aliases = [ "art.mekanoe.com" ]; };

      "doll.repair" = static { src = flakePackage "doll-repair"; };
      "blood.pet" = static { src = flakePackage "blood-pet"; };

      "foxxolay.com" = static {
        url = "https://github.com/foxxolay/foxxolay.com.git";
        rev = "d7b00d742d9f209c0be569aa95abfa32c42cc1c3";
      };

      "kitsu.love" = static {
        url = "https://codeberg.org/Vivieraaa/kitsu-site.git";
        rev = "c54f83ae4d094a64287c6054c43ecb132b7e240d";
      };
    };
  };
}
