aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/tools/commento/default.nix
blob: d0e7d2457a7328954784975e8f1765d7bfc5f1d7 (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
{ lib, pkgs, config, ... }:
let
  cfg = config.myServices.websites.tools.commento;
  env = config.myEnv.tools.commento;
  webPort = "${host}:${port}";
  port = toString env.listenPort;
  host = "localhost";
  postgresql_url = "postgres://${env.postgresql.user}:${env.postgresql.password}@localhost:${env.postgresql.port}/${env.postgresql.database}?sslmode=disable";
in
{
  options.myServices.websites.tools.commento = {
    enable = lib.mkEnableOption "Enable commento website";
  };
  config = lib.mkIf cfg.enable {
    secrets.keys = [
      {
        dest = "commento/env";
        permission = "0400";
        text = ''
          COMMENTO_ORIGIN=https://commento.immae.eu/
          COMMENTO_PORT=${port}
          COMMENTO_POSTGRES=${postgresql_url}
          COMMENTO_FORBID_NEW_OWNERS=true
          COMMENTO_BIND_ADDRESS=${host}
          COMMENTO_GZIP_STATIC=true
          COMMENTO_SMTP_HOST=${env.smtp.host}
          COMMENTO_SMTP_PORT=${env.smtp.port}
          COMMENTO_SMTP_USERNAME=${env.smtp.email}
          COMMENTO_SMTP_PASSWORD=${env.smtp.password}
          COMMENTO_SMTP_FROM_ADDRESS=${env.smtp.email}
        '';
      }
    ];

    services.websites.env.tools.vhostConfs.commento = {
      certName = "eldiron";
      addToCerts = true;
      hosts = [ "commento.immae.eu" ];
      root = null;
      extraConfig = [
        ''
          ProxyPass / http://${webPort}/
          ProxyPassReverse / http://${webPort}/
          ProxyPreserveHost On
        ''
      ];
    };
    systemd.services.commento = {
      description = "Commento";
      wantedBy = [ "multi-user.target" ];
      requires = ["postgresql.service"];
      after = ["network.target" "postgresql.service"];
      serviceConfig = {
        User = "wwwrun";
        ExecStart = "${pkgs.commento}/commento";
        EnvironmentFile = config.secrets.fullPaths."commento/env";
      };
    };
  };
}