summaryrefslogtreecommitdiff
path: root/config/stats.nix
blob: d30f426ef395566998b0f0d1a7f74c6b4b8b8412 (plain)
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
{ config, lib, pkgs, ... }:
let
  home = (import ../data/aliases.nix).services.stats.home;
  stats-pkg = "/opt/site/stats";
in
{
  services.postgresql = {
    enable = true;
    extraConfig = ''
      track_commit_timestamp = on
    '';
  };

  systemd.services.stats-init = {
    wantedBy = ["multi-user.target"];
    requires = ["postgresql.service"];
    after = ["postgresql.service"];
    script = ''
      if [[ ! -e ${home}/.db-created ]]; then
        ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createuser stats
        ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createdb -O stats stats
        touch ${home}/.db-created
      fi

      ${pkgs.sudo}/bin/sudo -u stats ${stats-pkg}/result/bin/stats --db postgresql://stats:stats@localhost/stats init
    '';
  };

  # systemd.services.stats-currency-fetch = {
  #   environment = { RUST_LOG = "stats=info"; };
  #   serviceConfig.ExecStart = "${stats-pkg}/target/debug/stats --db postgresql://orbekk:orbekk@localhost/stats currency";
  # };
  # systemd.timers.stats-currency-fetch = {
  #   wantedBy = [ "timers.target" ]; 
  #   timerConfig = {
  #     OnBootSec = "5m";
  #     OnUnitInactiveSec = "5m";
  #   };
  # };
  #
  # systemd.services.stats-currency-dash = {
  #   path = [ pkgs.nix ];
  #   wantedBy = ["multi-user.target"];
  #   serviceConfig.ExecStart = "${stats-pkg}/R/dashboard.sh";
  #   requires = ["stats-currency-fetch.service"];
  #   after = ["stats-currency-fetch.service"];
  #};
}