From 9a1fa4e418862aae216cf215c6f061dbdd9983fd Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 5 Mar 2023 20:39:15 +0100 Subject: [PATCH] cluster/services/consul: init --- cluster/services/consul/agent.nix | 24 ++++++++++++++++++++++++ cluster/services/consul/default.nix | 17 +++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 cluster/services/consul/agent.nix create mode 100644 cluster/services/consul/default.nix diff --git a/cluster/services/consul/agent.nix b/cluster/services/consul/agent.nix new file mode 100644 index 0000000..45bf4b0 --- /dev/null +++ b/cluster/services/consul/agent.nix @@ -0,0 +1,24 @@ +{ config, cluster, lib, ... }: + +let + inherit (config.networking) hostName; + inherit (cluster.config) hostLinks; + cfg = cluster.config.services.consul; + + hl = hostLinks.${hostName}.consul; +in + +{ + services.consul = { + enable = true; + webUi = true; + extraConfig = { + datacenter = "pve1"; + server = true; + node_name = config.networking.hostName; + bind_addr = hl.ipv4; + ports.serf_lan = hl.port; + retry_join = map (hostName: hostLinks.${hostName}.consul.tuple) cfg.otherNodes.agent; + }; + }; +} diff --git a/cluster/services/consul/default.nix b/cluster/services/consul/default.nix new file mode 100644 index 0000000..ae40b98 --- /dev/null +++ b/cluster/services/consul/default.nix @@ -0,0 +1,17 @@ +{ config, lib, ... }: + +let + cfg = config.services.consul; +in + +{ + hostLinks = lib.genAttrs cfg.nodes.agent (hostName: { + consul = { + ipv4 = config.vars.mesh.${hostName}.meshIp; + }; + }); + services.consul = { + nodes.agent = [ "checkmate" "VEGAS" ]; + nixos.agent = ./agent.nix; + }; +}