default.nix (2331B)
1 { 2 lib, 3 options, 4 config, 5 pkgs, 6 ... 7 }: 8 { 9 options.modules.bind = { 10 enable = lib.mkOption { 11 description = "Whether to enable BIND."; 12 default = false; 13 type = lib.types.bool; 14 }; 15 domain = lib.mkOption { 16 description = "The domain to setup DNS for."; 17 type = lib.types.uniq lib.types.str; 18 }; 19 records = lib.mkOption { 20 description = "The DNS records."; 21 default = [ ]; 22 type = 23 lib.types.submodule { 24 options = { 25 name = lib.mkOption { 26 description = "The name of the record."; 27 type = lib.types.uniq lib.types.str; 28 }; 29 ttl = lib.mkOption { 30 description = "The TTL of the record."; 31 type = lib.types.uniq lib.types.int; 32 }; 33 class = lib.mkOption { 34 description = "The class of the record."; 35 type = lib.types.uniq lib.types.str; 36 }; 37 type = lib.mkOption { 38 description = "The type of the record."; 39 type = lib.types.uniq lib.types.str; 40 }; 41 data = lib.mkOption { 42 description = "The data of the record."; 43 type = lib.types.uniq lib.types.str; 44 }; 45 }; 46 } 47 |> lib.types.listOf; 48 }; 49 }; 50 51 config = lib.mkIf config.modules.bind.enable { 52 services.bind = { 53 enable = true; 54 package = pkgs.bind; 55 56 zones.${config.modules.bind.domain} = { 57 master = true; 58 file = 59 config.modules.bind.records 60 |> builtins.map ( 61 { 62 name, 63 ttl, 64 class, 65 type, 66 data, 67 }: 68 let 69 inherit (config.modules.bind) domain; 70 subdomain = if name != "@" then "${name}." else ""; 71 in 72 [ 73 "${subdomain}${domain}." 74 (builtins.toString ttl) 75 class 76 type 77 data 78 ] 79 |> builtins.concatStringsSep " " 80 ) 81 |> builtins.concatStringsSep "\n" 82 |> pkgs.writeText "${config.modules.bind.domain}"; 83 }; 84 }; 85 86 networking.firewall = { 87 allowedTCPPorts = [ 53 ]; 88 allowedUDPPorts = [ 53 ]; 89 }; 90 }; 91 }