about summary refs log tree commit diff
path: root/modules/nixos/searx.nix
blob: de51a20f7a13ee674953e1d1822c5e1daf2b9783 (plain) (blame)
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
74
75
76
77
78
79
80
81
{
  config,
  inputs,
  lib,
  libNginx,
  ...
}:
with lib;
let
  cfg = config.nixfiles.modules.searx;
in
{
  options.nixfiles.modules.searx = {
    enable = mkEnableOption "SearX";

    port = mkOption {
      description = "Port.";
      type = with types; port;
      default = 61001;
    };

    domain = mkOption {
      description = "Domain name sans protocol scheme.";
      type = with types; nullOr str;
      default = "searx.${config.networking.domain}";
    };
  };

  config = mkIf cfg.enable {
    secrets.searx-environment = {
      file = "${inputs.self}/secrets/searx-environment";
      owner = "searx";
      group = "searx";
    };

    nixfiles.modules.nginx = {
      enable = true;
      upstreams.searx.servers."127.0.0.1:${toString cfg.port}" = { };
      virtualHosts.${cfg.domain} = {
        locations."/".proxyPass = "http://searx";
        extraConfig = libNginx.config.internalOnly;
      };
    };

    services = {
      searx = {
        enable = true;

        settings = {
          general = {
            instance_name = cfg.domain;
            contact_url = "mailto:admin+searx@${config.networking.domain}";
            git_url = false;
            git_branch = false;
            docs_url = false;
            wiki_url = false;
            twitter_url = false;
          };
          server = {
            bind_address = "127.0.0.1";
            inherit (cfg) port;
            secret_key = "@SEARX_SECRET_KEY@";
            base_url = false;
            image_proxy = false;
            default_http_headers = {
              Referrer-Policy = "no-referrer";
              X-Content-Type-Options = "nosniff";
              X-Download-Options = "noopen";
              X-Robots-Tag = "noindex, nofollow, nosnippet, noarchive";
            };
          };
          search = {
            safe_search = 0;
            autocomplete = "";
          };
        };
        environmentFile = config.secrets.searx-environment.path;
      };
    };
  };
}

Consider giving Nix/NixOS a try! <3