From e9b28a79ec7da5528aae3a0271bf8d2727a8d5f2 Mon Sep 17 00:00:00 2001
From: Florian Sesser <florian@private.storage>
Date: Fri, 11 Feb 2022 09:01:34 +0000
Subject: [PATCH] Move promtail service config to promtail config

Do some name resolution for those poor computers

Improve factoring by removing those `/etc/hosts` entries

And avoid the infinite loop @tomprince was encountering in !258
---
 morph/lib/base.nix                              |  7 -------
 nixos/modules/monitoring/exporters/promtail.nix | 10 +++++++++-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/morph/lib/base.nix b/morph/lib/base.nix
index aafbf4f4..3bc6ae4c 100644
--- a/morph/lib/base.nix
+++ b/morph/lib/base.nix
@@ -57,13 +57,6 @@
     # qualified domain name.
     deployment.targetHost = config.networking.fqdn;
 
-    networking.hosts = {
-      # To stream logs to the monitoring host, all nodes need to know its address
-      ${nodes.monitoring.config.services.private-storage.monitoring.vpn.server.ip} = [
-        "monitoring" "monitoring.monitoringvpn"
-      ];
-    };
-
     services.private-storage.monitoring.exporters.promtail.enable = true;
 
     assertions = [
diff --git a/nixos/modules/monitoring/exporters/promtail.nix b/nixos/modules/monitoring/exporters/promtail.nix
index e279b481..ca22c4ac 100644
--- a/nixos/modules/monitoring/exporters/promtail.nix
+++ b/nixos/modules/monitoring/exporters/promtail.nix
@@ -15,6 +15,14 @@ let
 in {
   options.services.private-storage.monitoring.exporters.promtail = {
     enable = lib.mkEnableOption "Promtail log exporter service";
+    lokiUrl = lib.mkOption {
+      type = lib.types.str;
+      description = ''
+        The server URL that logs should be pushed to.
+      '';
+      # Resolving names is hard, let's have breakfast
+      default = "http://172.23.23.1:3100/loki/api/v1/push";
+    };
   };
 
   config = lib.mkIf cfg.enable {
@@ -28,7 +36,7 @@ in {
       };
 
       clients = [{
-          url = "http://monitoring:3100/loki/api/v1/push";
+          url = cfg.lokiUrl;
       }];
 
       scrape_configs = [{
-- 
GitLab