Commit 7cc3f54c authored by Cryolitia PukNgae's avatar Cryolitia PukNgae Committed by Cryolitia PukNgae
Browse files

nixos/whois: init module

Add a NixOS module for the whois client.

This module installs the package and generates /etc/whois.conf from
programs.whois.settings.
parent 1ac9389e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -110,6 +110,8 @@

- [Tdarr](https://tdarr.io), Audio/Video Library Analytics & Transcode/Remux Automation. Available as [services.tdarr](#opt-services.tdarr.enable)

- [whois](https://packages.qa.debian.org/w/whois.html), an intelligent WHOIS client. Available as `programs.whois`.

## Backward Incompatibilities {#sec-release-26.05-incompatibilities}

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
+1 −0
Original line number Diff line number Diff line
@@ -357,6 +357,7 @@
  ./programs/wayland/wayfire.nix
  ./programs/wayland/wayvnc.nix
  ./programs/weylus.nix
  ./programs/whois.nix
  ./programs/winbox.nix
  ./programs/wireshark.nix
  ./programs/wshowkeys.nix
+89 −0
Original line number Diff line number Diff line
{
  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 ];
}