summaryrefslogtreecommitdiffstats
path: root/nixos/modules/programs/whois.nix
blob: e072dcf225fde2001f5f409088351631879fca40 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{
  config,
  lib,
  pkgs,
  ...
}:

let
  cfg = config.programs.whois;

  configText =
    lib.concatStringsSep "\n" (
      [
        "# Generated by NixOS."
        "# See whois.conf(5) for the file format."
      ]
      ++ map (entry: "${entry.pattern} ${entry.server}") cfg.settings
    )
    + "\n";
in

{
  options.programs.whois = {
    enable = lib.mkEnableOption "whois, an intelligent WHOIS client";

    package = lib.mkPackageOption pkgs "whois" { };

    settings = lib.mkOption {
      type = lib.types.listOf (
        lib.types.submodule {
          options = {
            pattern = lib.mkOption {
              type = lib.types.str;
              example = "\\.dn42$";
              description = ''
                Case-insensitive extended regular expression used to match the
                WHOIS object identifier.
              '';
            };

            server = lib.mkOption {
              type = lib.types.str;
              example = "whois.dn42";
              description = ''
                WHOIS server to use when {option}`pattern` matches.
              '';
            };
          };
        }
      );
      default = [ ];
      example = lib.literalExpression ''
        [
          {
            pattern = "\\.dn42$";
            server = "whois.dn42";
          }
          {
            pattern = "\\-DN42$";
            server = "whois.dn42";
          }
          {
            pattern = "^as424242[0-9]{4}$";
            server = "whois.dn42";
          }
          {
            pattern = "^172\\.2[0-3]\\.[0-9]{1,3}\\.[0-9]{1,3}(/(1[56789]|2[0-9]|3[012]))?$";
            server = "whois.dn42";
          }
        ]
      '';
      description = ''
        WHOIS configuration entries written to {file}`/etc/whois.conf`.

        Entries are written in the declared order, which matters when multiple
        patterns may match the same query.
      '';
    };

  };

  config = lib.mkIf cfg.enable {
    environment.systemPackages = [ cfg.package ];

    environment.etc."whois.conf".text = configText;
  };

  meta.maintainers = with lib.maintainers; [ Cryolitia ];
}