From edf770eb5a27fcc33a7bc23a9b5ba0b314e909ef Mon Sep 17 00:00:00 2001 From: Petru Paler Date: Thu, 6 Jul 2023 06:27:35 +0100 Subject: [PATCH] Basic consul config. --- flake.lock | 12 ++++++------ hosts/common/compute-node.nix | 1 + hosts/common/consul.nix | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/flake.lock b/flake.lock index d011125..207b442 100644 --- a/flake.lock +++ b/flake.lock @@ -55,11 +55,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1687829761, - "narHash": "sha256-QRe1Y8SS3M4GeC58F/6ajz6V0ZLUVWX3ZAMgov2N3/g=", + "lastModified": 1688482527, + "narHash": "sha256-9zd0YC2gfsRvVJENZsVs1R5LBj5/t127JlCLggn/970=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9790f3242da2152d5aa1976e3e4b8b414f4dd206", + "rev": "c7a18f89ef1dc423f57f3de9bd5d9355550a5d15", "type": "github" }, "original": { @@ -71,11 +71,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1688049487, - "narHash": "sha256-100g4iaKC9MalDjUW9iN6Jl/OocTDtXdeAj7pEGIRh4=", + "lastModified": 1688500189, + "narHash": "sha256-djYYiY4lzJOlXOnTHytH6BUugrxHDZjuGxTSrU4gt4M=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4bc72cae107788bf3f24f30db2e2f685c9298dc9", + "rev": "78419edadf0fabbe5618643bd850b2f2198ed060", "type": "github" }, "original": { diff --git a/hosts/common/compute-node.nix b/hosts/common/compute-node.nix index 34566d8..d4a9f64 100644 --- a/hosts/common/compute-node.nix +++ b/hosts/common/compute-node.nix @@ -1,6 +1,7 @@ { pkgs, ... }: { imports = [ + ./consul.nix ./impermanence.nix ./nomad.nix ./seaweedfs.nix diff --git a/hosts/common/consul.nix b/hosts/common/consul.nix index 6356107..f107aee 100644 --- a/hosts/common/consul.nix +++ b/hosts/common/consul.nix @@ -1,8 +1,22 @@ { pkgs, config, ... }: +let + servers = [ "c1" "c2" "c3" ]; + server_enabled = builtins.elem config.networking.hostName servers; +in { - services.consul.enable = true; + services.consul = { + enable = true; + interface.advertise = "eno1"; + extraConfig = { + datacenter = "alo"; + server = server_enabled; + bootstrap_expect = (builtins.length servers + 2) / 2; + retry_join = builtins.filter (elem: elem != config.networking.hostName) servers; + }; + }; environment.persistence."/persist".directories = [ + "/var/lib/consul" ]; networking.firewall = {