From 5a06ab74bbbf2f119c5b388b1544442b18b76d19 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 24 Apr 2021 23:08:43 +0000 Subject: [PATCH] lib: ip: add 'nth' utility to 'parseSubnet4' --- lib/ip.nix | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ip.nix b/lib/ip.nix index f499072..40c40c0 100644 --- a/lib/ip.nix +++ b/lib/ip.nix @@ -75,9 +75,22 @@ rec { "which will get masked to ${prettyIp4 baseIp}," "which should be used instead" ]); + nth = n: + let + result = nthInRange4 range n; + try = + if check result + then id + else + warn (concatStringsSep " " [ + "nth call with n = ${toString n}" + "is out of range for subnet ${str}" + ]); + in + try result; in try { - inherit baseIp check cidr mask range; + inherit baseIp check cidr mask nth range; }; # Pretty print a parsed IPv4 address into a human readable form