aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2021-05-16 18:25:26 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2021-05-16 18:25:26 +0200
commit11c2119f776263b103721302fdd3f2ba8c985bc1 (patch)
tree6dd45290acf42b607f9dbd988a5f6df22899c38d /modules
parent3db907f82f735107d9697c28db502844b000f958 (diff)
downloadNix-11c2119f776263b103721302fdd3f2ba8c985bc1.tar.gz
Nix-11c2119f776263b103721302fdd3f2ba8c985bc1.tar.zst
Nix-11c2119f776263b103721302fdd3f2ba8c985bc1.zip
Remove duplicates when generating server list in bind
Diffstat (limited to 'modules')
-rw-r--r--modules/private/dns.nix15
1 files changed, 12 insertions, 3 deletions
diff --git a/modules/private/dns.nix b/modules/private/dns.nix
index 1149daf..7c59b43 100644
--- a/modules/private/dns.nix
+++ b/modules/private/dns.nix
@@ -2,16 +2,25 @@
2{ 2{
3 options.myServices.dns.enable = lib.mkEnableOption "enable DNS resolver"; 3 options.myServices.dns.enable = lib.mkEnableOption "enable DNS resolver";
4 config = let 4 config = let
5 # taken from unstable
6 cartesianProductOfSets = attrsOfLists: with lib;
7 lib.foldl' (listOfAttrs: attrName:
8 concatMap (attrs:
9 map (listValue: attrs // { ${attrName} = listValue; }) attrsOfLists.${attrName}
10 ) listOfAttrs
11 ) [{}] (attrNames attrsOfLists);
5 cfg = config.services.bind; 12 cfg = config.services.bind;
6 keyIncludes = builtins.concatStringsSep "\n" (map (v: "include \"/var/secrets/bind/${v}.key\";") (builtins.attrNames config.myEnv.dns.keys)); 13 keyIncludes = builtins.concatStringsSep "\n" (map (v: "include \"/var/secrets/bind/${v}.key\";") (builtins.attrNames config.myEnv.dns.keys));
14 cartProduct = lib.foldr
15 (s: servers: servers // { ${s.masters} = lib.unique ((servers.${s.masters} or []) ++ [s.keys]); })
16 {}
17 (lib.unique (lib.concatMap (z: cartesianProductOfSets { masters = z.masters or []; keys = z.keys or []; }) config.myEnv.dns.slaveZones));
7 toKeyList = servers: keys: builtins.concatStringsSep "\n" (map (s: '' 18 toKeyList = servers: keys: builtins.concatStringsSep "\n" (map (s: ''
8 server ${s} { 19 server ${s} {
9 keys { ${builtins.concatStringsSep ";" keys}; }; 20 keys { ${builtins.concatStringsSep ";" keys}; };
10 }; 21 };
11 '') servers); 22 '') servers);
12 serverIncludes = builtins.concatStringsSep "\n" (map (v: 23 serverIncludes = builtins.concatStringsSep "\n" (lib.mapAttrsToList (n: toKeyList (lib.flatten (builtins.attrValues config.myEnv.dns.ns."${n}"))) cartProduct);
13 lib.optionalString (builtins.length v.keys > 0) (toKeyList (lib.flatten (map (n: builtins.attrValues config.myEnv.dns.ns."${n}") v.masters)) v.keys)
14 ) config.myEnv.dns.slaveZones);
15 configFile = pkgs.writeText "named.conf" '' 24 configFile = pkgs.writeText "named.conf" ''
16 include "/etc/bind/rndc.key"; 25 include "/etc/bind/rndc.key";
17 controls { 26 controls {