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; + }; +}