{ 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"]; #}; }