summaryrefslogtreecommitdiff
path: root/os/srv/omnisearch.nix
blob: ac361848de2838d38a80cf847a5925e9979b8db4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{
  config,
  lib,
  inputs,
  masterDomain,
  templates,
  ...
}:
let
  cfg = config.os.srv.omnisearch;
in
{
  imports = [ inputs.omnisearch.nixosModules.default ];

  options.os.srv.omnisearch = {
    enable = lib.mkEnableOption "enables omnisearch tracking infrastructure";

    role = lib.mkOption {
      type = lib.types.enum [
        "server"
        "standalone"
      ];
      default = "standalone";
      description = "Designates the deployment method";
    };
  };

  config = lib.mkIf cfg.enable (
    lib.mkMerge [
      {
        services.omnisearch = {
          enable = true;
          settings = {
            server = {
              host = "127.0.0.1";
              port = 8087;
              locale = "en";
              domain = if cfg.role == "server" then "https://search.${masterDomain}" else "http://localhost:8087";
            };
            proxy = {
              max_retries = 3;
              randomize_username = true;
              randomize_password = true;
            };
            cache = {
              dir = "/var/cache/omnisearch";
              ttl_search = 1800;
              ttl_infobox = 86400;
            };
          };
        };
      }

      (lib.mkIf (cfg.role == "server") {
        assertions = [
          {
            assertion = config.os.srv.nginx.enable;
            message = "Required for proxying";
          }
        ];
        services.nginx.virtualHosts."search.${masterDomain}" = {
          enableACME = true;
          forceSSL = true;
          locations."/" = {
            proxyPass = "http://127.0.0.1:8087";
            proxyWebsockets = true;
            extraConfig = templates.restrictToInternal;
          };
        };
      })
    ]
  );
}