summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2017-10-19 21:42:08 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2017-10-19 21:42:08 -0400
commit1e28c12b035dac4b862fbb86bbdc6d1e5b03fdd1 (patch)
tree27568eed3cb4755e054f0a62c762f5381e82ee8a /config
parenta063c3f934c8bb7d2bc473b25c17ced48d6c7e95 (diff)
add: Stats config
Diffstat (limited to 'config')
-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