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

  imports = [
    ../hardware/ai.nix
    ./headless.nix
    (import ./networking.nix {
      hostname = "mindforge";
      ip_address = "192.168.100.45";
      open_ports = [ 80 443 ];
      inherit lib;
    })
  ];

  users.users.mindforge = import ./user.nix;

  services.ollama = {
    enable = true;
    host = "0.0.0.0";
    openFirewall = true;
    environmentVariables = {
        OLLAMA_CONTEXT_LENGTH = "8192";
    };
  };

  # NGINX Reverse Proxy Setup
  services.open-webui.enable = true;
  services.nginx = {
    enable = true;
    virtualHosts = {
      # Jellyfin
      "mindforge.randomctf.local" = {
        extraConfig = ''
          access_log /var/log/nginx/access.mindforge.log;
        '';

        locations."/".extraConfig = ''
          proxy_pass http://localhost:8080/;

          # Add WebSocket support (Necessary for version 0.5.0 and up)
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";

          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;

          proxy_buffering off;
        '';
      };
    };
  };
}
