{ config, pkgs, lib, mkDomain, ... }:
{
  # redlib, previously libreddit
  # Private front-end for Reddit

  services.redlib = {
    enable = true;
    address = "127.0.0.1";
    port = 4876;
  };
  systemd.services.redlib.environment = lib.mkIf config.services.redlib.enable {
    # https://github.com/redlib-org/redlib?tab=readme-ov-file#default-user-settings
    # TODO: merge my module addition
    REDLIB_DEFAULT_THEME = "gold";
  };
  services.nginx.virtualHosts.${mkDomain "redlib"} = lib.mkIf config.services.redlib.enable {
    /* serverAliases = [ (mkDomain "libreddit") ]; */
    forceSSL = true; # addSSL = true;
    enableACME = true; #useACMEHost = acmeDomain;
    locations."/" = {
      proxyPass = "http://127.0.0.1:${toString config.services.redlib.port}";
      proxyWebsockets = true;
    };
  };
  services.nginx.virtualHosts.${mkDomain "libreddit"} = lib.mkIf config.services.redlib.enable {
    forceSSL = true; # addSSL = true;
    enableACME = true; #useACMEHost = acmeDomain;
    locations."/".extraConfig = ''
      return 301 https://${mkDomain "redlib"}$request_uri;
    '';
  };

}
