all repos — nixfiles @ 3457d2c64e13ae5b6301076388536ca1fb62d7ca

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
46
47
48
49
50
51
52
{
  config,
  ...
}:
let
  domain = config.networking.domain;
in
{
  imports = [
    ./mailer.nix
    ../settings/programs/sqlite.nix
  ];

  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
      {
        # TODO: switch to on-demand TLS
        # useACMEHost = "stats.${domain}";
        # serverAliases = [ "*.stats.${domain}" ];
        extraConfig = ''
          reverse_proxy ${srv.address}:${toString srv.port}
        '';
      };
  };

  ## actalis doesn't allow wildcard on free tier
  # security.acme.certs."stats.${domain}" = {
  #   extraDomainNames = [ "*.stats.${domain}" ];
  # };
}