Unverified Commit 757a455d authored by eyjhb's avatar eyjhb
Browse files

nixos/bind: refactor zones from a list to attrset

This commit uses coercedTo to make zones a attrset instead of list.
Makes it easier to access/change zones in multiple places.
parent 2bd34a98
Loading
Loading
Loading
Loading
+42 −36
Original line number Diff line number Diff line
@@ -8,9 +8,13 @@ let

  bindUser = "named";

  bindZoneOptions = {
  bindZoneCoerce = list: builtins.listToAttrs (lib.forEach list (zone: { name = zone.name; value = zone; }));

  bindZoneOptions = { name, config, ... }: {
    options = {
      name = mkOption {
        type = types.str;
        default = name;
        description = "Name of the zone.";
      };
      master = mkOption {
@@ -36,6 +40,7 @@ let
        default = "";
      };
    };
  };

  confFile = pkgs.writeText "named.conf"
    ''
@@ -84,7 +89,7 @@ let
                ${extraConfig}
              };
            '')
          cfg.zones }
          (attrValues cfg.zones) }
    '';

in
@@ -153,18 +158,19 @@ in

      zones = mkOption {
        default = [];
        type = types.listOf (types.submodule [ { options = bindZoneOptions; } ]);
        type = with types; coercedTo (listOf attrs) bindZoneCoerce (attrsOf (types.submodule bindZoneOptions));
        description = "
          List of zones we claim authority over.
        ";
        example = [{
          name = "example.com";
        example = {
          "example.com" = {
            master = false;
            file = "/var/dns/example.com";
            masters = ["192.168.0.1"];
            slaves = [];
            extraConfig = "";
        }];
          };
        };
      };

      extraConfig = mkOption {