Unverified Commit d3143804 authored by Pol Dellaiera's avatar Pol Dellaiera Committed by GitHub
Browse files

nixos/whois: init module (#502911)

parents 3c2717fd 8c4a9691
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 ];
}
+1 −0
Original line number Diff line number Diff line
@@ -1746,6 +1746,7 @@ in
  wg-access-server = runTest ./wg-access-server.nix;
  whisparr = runTest ./whisparr.nix;
  whoami = runTest ./whoami.nix;
  whois = runTest ./whois.nix;
  whoogle-search = runTest ./whoogle-search.nix;
  wiki-js = runTest ./wiki-js.nix;
  windmill = import ./windmill {

nixos/tests/whois.nix

0 → 100644
+43 −0
Original line number Diff line number Diff line
{ lib, ... }:
{
  name = "whois";
  meta.maintainers = with lib.maintainers; [ Cryolitia ];

  nodes.machine = {
    imports = [ ../modules/profiles/minimal.nix ];

    programs.whois = {
      enable = true;
      settings = [
        {
          pattern = "\\.dn42$";
          server = "whois.dn42";
        }
        {
          pattern = "\\-DN42$";
          server = "whois.dn42";
        }
        {
          pattern = "^as424242[0-9]{4}$";
          server = "whois.dn42";
        }
      ];
    };
  };

  testScript = ''
    start_all()

    machine.succeed("command -v whois")

    whois_conf = machine.succeed("cat /etc/whois.conf").strip()
    expected = """
    # Generated by NixOS.
    # See whois.conf(5) for the file format.
    \\.dn42$ whois.dn42
    \\-DN42$ whois.dn42
    ^as424242[0-9]{4}$ whois.dn42
    """.strip()
    assert whois_conf == expected
  '';
}