summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/stats.nix48
1 files changed, 48 insertions, 0 deletions
diff --git a/config/stats.nix b/config/stats.nix
new file mode 100644
index 0000000..d30f426
--- /dev/null
+++ b/config/stats.nix
@@ -0,0 +1,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"];
+ #};
+} \ No newline at end of file