lib: ip: add 'nth' utility to 'parseSubnet4'
This commit is contained in:
parent
1968285d0a
commit
5a06ab74bb
15
lib/ip.nix
15
lib/ip.nix
|
@ -75,9 +75,22 @@ rec {
|
||||||
"which will get masked to ${prettyIp4 baseIp},"
|
"which will get masked to ${prettyIp4 baseIp},"
|
||||||
"which should be used instead"
|
"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
|
in
|
||||||
try {
|
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
|
# Pretty print a parsed IPv4 address into a human readable form
|
||||||
|
|
Loading…
Reference in a new issue