diff --git a/nixos/doc/manual/release-notes/rl-2605.section.md b/nixos/doc/manual/release-notes/rl-2605.section.md index 94b0b20232aa..44ddf089eacf 100644 --- a/nixos/doc/manual/release-notes/rl-2605.section.md +++ b/nixos/doc/manual/release-notes/rl-2605.section.md @@ -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} diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 5f6ca7c525d9..ab0b67fe0fc3 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -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 diff --git a/nixos/modules/programs/whois.nix b/nixos/modules/programs/whois.nix new file mode 100644 index 000000000000..e072dcf225fd --- /dev/null +++ b/nixos/modules/programs/whois.nix @@ -0,0 +1,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 ]; +} diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 4e11dbced014..cebf186a3bd2 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -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 { diff --git a/nixos/tests/whois.nix b/nixos/tests/whois.nix new file mode 100644 index 000000000000..49ec707e2631 --- /dev/null +++ b/nixos/tests/whois.nix @@ -0,0 +1,43 @@ +{ 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 + ''; +}