all repos — nixfiles @ 5b29c182763c1fbf0951b0e616acf1890e9385b2

System and user configuration, managed by nix and home-manager

system/roles/searchix.nix (view raw)

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
82
83
84
85
86
87
88
89
90
91
92
{
  config,
  pkgs,
  ...
}:
let
  port = toString config.services.searchix.settings.web.port;
in
{
  imports = [
    ../settings/services/searchix.nix
    ../../packages/modules/nixos/goaccess.nix
  ];

  services.searchix.settings.web = {
    baseURL = "https://searchix.ovh";
  };

  services.caddy.virtualHosts = {
    "searchix.ovh" = {
      extraConfig = ''
        root ${pkgs.searchix}/lib/searchix
        handle_errors {
          rewrite * /error.html
          templates
          file_server
        }
        handle_path /stats/* {
          root /srv/http/access/searchix
          file_server
        }
        handle {
          import rate_limit
          reverse_proxy {
            to localhost:${port}
            lb_policy first

            # active health checks (service running)
            health_uri /health
            health_status 2xx
            health_interval 10s
            health_timeout 2s
            health_fails 2

            # passive health checks
            max_fails 5
            fail_duration 30s
            unhealthy_status 5xx
          }
        }
        encode zstd gzip {
          match {
            header Content-Type text/*
            header Content-Type application/json*
            header Content-Type application/javascript*
            header Content-Type application/opensearchdescription+xml
            header Content-Type application/atom+xml*
            header Content-Type application/rss+xml*
            header Content-Type image/svg+xml*
          }
        }
      '';
    };
    "searchix.alanpearce.eu" = {
      extraConfig = ''
        redir https://searchix.ovh{uri} permanent
      '';
    };
  };

  services.goaccess = {
    user = "caddy";
    group = "caddy";
    instances = {
      searchix = {
        enable = true;
        dates = "hourly";
        settings = {
          log-file = "${config.services.caddy.logDir}/access-searchix.ovh.log";
          output = "/srv/http/access/searchix/index.html";
          log-format = "caddy";
          anonymize-ip = true;
          anonymize-level = 2;
          persist = true;
          restore = true;
          keep-last = 90; # days
        };
      };
    };
  };

}