X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Fprivate%2Fdns.nix;h=1d7fd52fb3fe6e11d27ea801da4f0518ee719069;hb=4c4652aabf2cb3ac8b40f2856eca07a1df9c27e0;hp=cb900ffad6ca725b9853666d6055c095117b716f;hpb=68ff82c61628212208bc339b9f91fd1dba6ade50;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/private/dns.nix b/modules/private/dns.nix index cb900ff..1d7fd52 100644 --- a/modules/private/dns.nix +++ b/modules/private/dns.nix @@ -2,7 +2,25 @@ { options.myServices.dns.enable = lib.mkEnableOption "enable DNS resolver"; config = let + # taken from unstable + cartesianProductOfSets = attrsOfLists: with lib; + lib.foldl' (listOfAttrs: attrName: + concatMap (attrs: + map (listValue: attrs // { ${attrName} = listValue; }) attrsOfLists.${attrName} + ) listOfAttrs + ) [{}] (attrNames attrsOfLists); cfg = config.services.bind; + keyIncludes = builtins.concatStringsSep "\n" (map (v: "include \"${config.secrets.fullPaths."bind/${v}.key"}\";") (builtins.attrNames config.myEnv.dns.keys)); + cartProduct = lib.foldr + (s: servers: servers // { ${s.masters} = lib.unique ((servers.${s.masters} or []) ++ [s.keys]); }) + {} + (lib.unique (lib.concatMap (z: cartesianProductOfSets { masters = z.masters or []; keys = z.keys or []; }) config.myEnv.dns.slaveZones)); + toKeyList = servers: keys: builtins.concatStringsSep "\n" (map (s: '' + server ${s} { + keys { ${builtins.concatStringsSep ";" keys}; }; + }; + '') servers); + serverIncludes = builtins.concatStringsSep "\n" (lib.mapAttrsToList (n: toKeyList (lib.flatten (builtins.attrValues config.myEnv.dns.ns."${n}"))) cartProduct); configFile = pkgs.writeText "named.conf" '' include "/etc/bind/rndc.key"; controls { @@ -24,6 +42,9 @@ ${cfg.extraOptions} }; + ${keyIncludes} + ${serverIncludes} + ${cfg.extraConfig} ${ lib.concatMapStrings @@ -65,6 +86,20 @@ in lib.mkIf config.myServices.dns.enable { networking.firewall.allowedUDPPorts = [ 53 ]; networking.firewall.allowedTCPPorts = [ 53 ]; + users.users.named.extraGroups = [ "keys" ]; + secrets.keys = lib.mapAttrs' (k: v: + lib.nameValuePair "bind/${k}.key" { + permissions = "0400"; + user = "named"; + text = '' + key "${k}" + { + algorithm ${v.algorithm}; + secret "${v.secret}"; + }; + ''; + } + ) config.myEnv.dns.keys; services.bind = { enable = true; cacheNetworks = ["any"];