about summary refs log tree commit diff
path: root/modules/services/searx.nix
blob: 143647489974988a9ca8cb37cc4c2bd99e623ca1 (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
{ config, lib, pkgs, ... }:

with lib;
let
  cfg = config.modules.services.searx;
in
{
  options.modules.services.searx = {
    enable = mkEnableOption "searx metasearch engine";
    package = mkOption { type = types.package; default = pkgs.searxng; };
    domain = mkOption { type = types.str; };
    realHost = mkOption { type = types.str; };
    secrets.searx-env = mkOption { type = types.str; description = "path to the searx secret envfile"; };
  };

  config = mkIf cfg.enable {
    services.searx = {
      enable = true;
      package = cfg.package;
      environmentFile = cfg.secrets.searx-env;
      runInUwsgi = true;
      settings = {
        use_default_settings = true;

        general.instance_name = "exotic.sh search";
        server.secret_key = "@SEARX_SECRET_KEY@";
      };
      uwsgiConfig = {
        socket = "/run/searx/searx.sock";
        chmod-socket = "660";
        cache2 = "name=searx_cache,items=2000,blocks=2000,blocksize=4096,bitmap=1";
        disable-logging = true; # public service
      };
    };

    users.extraUsers.nginx.extraGroups = [ "searx" ];

    services.nginx.virtualHosts.${cfg.realHost} = {
      forceSSL = true;
      useACMEHost = cfg.domain;
      locations."/".extraConfig = ''
        proxy_set_header Host $host;
        access_log off; # public service
        uwsgi_pass unix:/run/searx/searx.sock;
        include ${pkgs.nginx}/conf/uwsgi_params;
      '';
      locations."/static/".alias = "${cfg.package}/share/static/";
    };
  };
}