summary refs log tree commit diff
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-rw-r--r--services/goatcounter.nix63
1 files changed, 63 insertions, 0 deletions
diff --git a/services/goatcounter.nix b/services/goatcounter.nix
new file mode 100644
index 0000000..b463b27
--- /dev/null
+++ b/services/goatcounter.nix
@@ -0,0 +1,63 @@
+{
+  me,
+  pkgs,
+  auxiliaryPkgs,
+  ...
+}:
+
+let
+  inherit (pkgs) dockerTools;
+  inherit (auxiliaryPkgs) common;
+
+  goatcounter = pkgs.goatcounter;
+
+  goatcounterLocalPort = 7151;
+  goatcounterDir = "/srv/goatcounter";
+
+  goatcounterImage = dockerTools.streamLayeredImage {
+    name = "goatcounter";
+    tag = goatcounter.version;
+    fromImage = common.alpine.base;
+    contents = [ goatcounter ];
+  };
+
+in
+{
+  foundation.services.goatcounter = {
+    image = goatcounterImage;
+    ports = [
+      [
+        goatcounterLocalPort
+        8080
+      ]
+    ];
+
+    volumes = [
+      [
+        "${goatcounterDir}"
+        "/goatcounter"
+      ]
+    ];
+
+    entrypoint = "${goatcounter}/bin/goatcounter";
+    cmd = [
+      "serve"
+      "-automigrate"
+      "-listen=:8080"
+      "-tls=none"
+      "-db=sqlite+/goatcounter/db.sqlite3"
+    ];
+  };
+
+  services.nginx.virtualHosts."goat.rnrd.eu" = {
+    useACMEHost = "rnrd.eu";
+    forceSSL = true;
+    locations."/" = {
+      proxyPass = "http://127.0.0.1:${toString goatcounterLocalPort}/";
+      proxyWebsockets = true;
+    };
+    extraConfig = ''
+      access_log /var/log/nginx/goat.access.log json_combined;
+    '';
+  };
+}