all repos — nixfiles @ dc65b31e03fb7d4429895a227409f237687c9dbf

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

system/roles/goatcounter.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
{
  config,
  ...
}:
let
  domain = config.networking.domain;
in
{
  services.goatcounter = {
    enable = true;
    address = "localhost";
    port = 8082;
    proxy = true;
    extraArgs = [
      "-db"
      "sqlite3+db/goatcounter.sqlite3"
      "-websocket"
      "-automigrate"
      "-email-from"
      "goatcounter@${domain}"
      "-smtp"
      "smtp://localhost:25"
      "-ratelimit"
      "api-count:100/1"
    ];
  };

  services.caddy.virtualHosts = {
    "stats.${domain}" =
      let
        srv = config.services.goatcounter;
      in
      {
        useACMEHost = "stats.${domain}";
        serverAliases = [ "*.stats.${domain}" ];
        extraConfig = ''
          reverse_proxy ${srv.address}:${toString srv.port}
        '';
      };
  };

  security.acme.certs."stats.${domain}" = {
    extraDomainNames = [ "*.stats.${domain}" ];
  };
}