aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/tools/stats/default.nix
blob: 5f184bcc40b971c79f9574c81628cbaaf22c6ffd (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
{ config, lib, pkgs, ... }:
let
  cfg = config.myServices.websites.tools.stats;
  myCfg = config.myEnv.tools.umami;
in
{
  options.myServices.websites.tools.stats.enable = lib.mkEnableOption "Enable stats site";
  config = lib.mkIf cfg.enable {
    secrets.keys = [
      {
        dest = "umami/env";
        permission = "0400";
        text = ''
          PORT=${toString myCfg.listenPort}
          HOSTNAME=127.0.0.1
          DATABASE_URL=postgresql://${myCfg.postgresql.user}:${myCfg.postgresql.password}@localhost:${myCfg.postgresql.port}/${myCfg.postgresql.database}?sslmode=disable&host=${myCfg.postgresql.socket}
          HASH_SALT=${myCfg.hashSalt}
        '';
      }
    ];

    services.websites.env.tools.vhostConfs.stats = {
      certName = "eldiron";
      addToCerts = true;
      hosts = [ "stats.immae.eu" ];
      root = null;
      extraConfig = [
        ''
          ProxyPass / http://localhost:${toString myCfg.listenPort}/
          ProxyPassReverse / http://localhost:${toString myCfg.listenPort}/
          ProxyPreserveHost On
        ''
      ];
    };
    systemd.services.umami = {
      description = "Umami service";
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];
      wants = [ "postgresql.service" ];
      path = [ pkgs.nodejs pkgs.bashInteractive ];
      serviceConfig = {
        Type = "simple";
        User = "umami";
        Group = "umami";
        DynamicUser = true;
        SupplementaryGroups = [ "keys" ];
        ExecStart = "${pkgs.umami}/bin/umami";
        EnvironmentFile = config.secrets.fullPaths."umami/env";
      };
    };
  };
}