-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathzk-cluster.nix
47 lines (41 loc) · 1.52 KB
/
zk-cluster.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Zookeeper cluster configuration:
# - Add other servers to configuration
# - Add firewall rules
with import <nixpkgs/lib>;
{
defaults = { config, pkgs, nodes, ... }:
let
mapNodesToList = f: mapAttrsToList f nodes;
in let
mapNodesToString = f: concatStrings (mapNodesToList f);
in let
zkServers = mapNodesToString (nodeId: node:
let zk = node.config.services.zookeeper; in
optionalString zk.enable "server.${toString zk.id} = ${nodeId}:2888:3888\n"
);
allowOtherMasters = mapNodesToString (nodeId: node:
let zk = node.config.services.zookeeper; in
optionalString zk.enable ''
iptables -A nixos-fw -s ${nodeId} -p tcp -m multiport --dports 2888,3888 -m comment --comment "zk: allow master ${nodeId}" -j ACCEPT
''
);
allowAll = mapNodesToString (nodeId: node:
let zk = node.config.services.zookeeper; in
optionalString zk.enable ''
iptables -A nixos-fw -s ${nodeId} -p tcp --dport ${toString zk.port} -m comment --comment "zk: allow node ${nodeId}" -j ACCEPT
''
);
in
mkIf config.services.zookeeper.enable
{
services.zookeeper = {
servers = zkServers;
};
networking.firewall = {
# We allow other masters to master ports and other nodes to zk port, no-one else
extraCommands = allowOtherMasters + allowAll;
};
# Client binaries
environment.systemPackages = with pkgs; [ zookeeper ];
};
}