Compare commits

...

8 commits

10 changed files with 20 additions and 7 deletions

View file

@ -1,9 +1,8 @@
{ config, lib, name, ... }:
{ config, lib, ... }:
with lib;
let
filterGroup = group: hostName: builtins.filter (x: x != hostName) group;
serviceName = name;
in
{
@ -65,6 +64,11 @@ in
type = types.deferredModule;
default = {};
};
availableNodes = mkOption {
description = "Nodes to include in the scenario.";
type = with types; nullOr (listOf str);
default = null;
};
};
};
config.otherNodes = builtins.mapAttrs (const filterGroup) config.nodes;

View file

@ -25,7 +25,7 @@ in
bind_addr = hl.ipv4;
ports.serf_lan = hl.port;
retry_join = map (hostName: hostLinks.${hostName}.consul.tuple) (cfg.otherNodes.agent hostName);
bootstrap_expect = builtins.length cfg.nodes.agent;
bootstrap_expect = 3;
addresses.http = config.links.consulAgent.ipv4;
ports.http = config.links.consulAgent.port;
};

View file

@ -26,6 +26,7 @@ in
enable = true;
deps = [ "wireguard" ];
settings = ./test.nix;
availableNodes = lib.take 3 cfg.nodes.agent;
};
};

View file

@ -60,6 +60,7 @@ in
enable = true;
deps = [ "consul" "acme-client" "patroni" ];
settings = ./test.nix;
availableNodes = cfg.nodes.authoritative;
};
};

View file

@ -41,6 +41,7 @@
enable = true;
deps = [ "consul" "incandescence" "locksmith" ];
settings = ./simulacrum/test.nix;
availableNodes = config.services.patroni.nodes.worker;
};
};
}

View file

@ -58,6 +58,7 @@ in
enable = true;
deps = [ "wireguard" "consul" "locksmith" "dns" "incandescence" "ways" ];
settings = ./simulacrum/test.nix;
availableNodes = config.services.storage.nodes.garage;
};
};

View file

@ -13,6 +13,7 @@
enable = true;
deps = [ "nginx" "acme-client" "dns" "certificates" "consul" ];
settings = ./simulacrum/test.nix;
availableNodes = lib.take 3 config.services.ways.nodes.host;
};
};

View file

@ -20,7 +20,7 @@ in
};
};
}
(lib.genAttrs cluster.config.services.ways.nodes.host (lib.const {
(lib.genAttrs cluster.config.services.ways.simulacrum.availableNodes (lib.const {
services.nginx.upstreams.nowhere.servers = {
"${(builtins.head config.nodes.nowhere.networking.interfaces.eth1.ipv4.addresses).address}:8080" = {};
};

View file

@ -22,8 +22,10 @@ let
};
};
nodes = lib.attrNames config.gods.fromLight;
nodes' = lib.attrNames (config.gods.fromLight // { nowhere = null; });
nodesConfigured = config.cluster.config.services.${service}.simulacrum.availableNodes;
availableNodes = if nodesConfigured == null then config.gods.fromLight else lib.genAttrs nodesConfigured (_: throw "unreachable");
nodes = lib.attrNames availableNodes;
nodes' = lib.attrNames (availableNodes // { nowhere = null; });
digits = lib.attrsets.listToAttrs (lib.zipListsWith lib.nameValuePair nodes' (lib.range 1 255));
depot' = extendModules {
modules = [

View file

@ -52,6 +52,8 @@ let
genHostCert = hostname: genCert [ "--hostname=${hostname}" ] { CN = hostname; };
getNodeAddr = node: (builtins.head config.nodes.${node}.networking.interfaces.eth1.ipv4.addresses).address;
filterActiveNodes = lib.filterAttrs (node: _: config.nodes ? ${node});
in
{
@ -79,7 +81,7 @@ in
address = hour.interfaces.primary.addrPublic;
prefixLength = 32;
via = getNodeAddr name;
}) depot.gods.fromLight;
}) (filterActiveNodes depot.gods.fromLight);
nameservers = map (name: depot.hours.${name}.interfaces.primary.addrPublic) cluster.config.services.dns.nodes.authoritative;
};
services.nginx = {