{ pkgs, lib, config, ... }:
let
  cfg = config.mods.server;
  ports = cfg.nginx.ports;
in with lib; {
  options.mods.server = {
    videos = {
      enable = mkEnableOption {
        default = false;
        description = "enables invidious server";
      };
    };

    reddit = {
      enable = mkEnableOption {
        default = false;
        description = "enables redlib server";
      };
    };
  };

  config = {
    services.invidious = mkIf cfg.videos.enable {
      enable = true;
      address = "0.0.0.0";
      port = ports.videos;

      settings = {
        db.user = "invidious";
        db.dbname = "invidious";
      };
    };

    services.redlib = mkIf cfg.reddit.enable {
      enable = true;
      openFirewall = true;
      address = "0.0.0.0";
      port = ports.reddit;
    };
  };
}
