feat(lib): add domain manipulation functions
This commit is contained in:
parent
1912666242
commit
83e7043eb5
1 changed files with 22 additions and 1 deletions
|
@ -1,5 +1,20 @@
|
||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
{
|
let
|
||||||
|
inherit (lib) singleton;
|
||||||
|
inherit (lib.strings) splitString;
|
||||||
|
inherit (builtins) length concatStringsSep tail;
|
||||||
|
in
|
||||||
|
rec {
|
||||||
|
# Helpers
|
||||||
|
splitDomain = domain: splitString "." domain;
|
||||||
|
shortenList =
|
||||||
|
count: list:
|
||||||
|
let
|
||||||
|
len = length list;
|
||||||
|
in
|
||||||
|
if len <= count then list else (shortenList count (tail list));
|
||||||
|
|
||||||
|
# Modules
|
||||||
mkStrOption = lib.mkOption {
|
mkStrOption = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = "";
|
default = "";
|
||||||
|
@ -16,4 +31,10 @@
|
||||||
type = lib.types.path;
|
type = lib.types.path;
|
||||||
default = path;
|
default = path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Domains
|
||||||
|
isRootDomain = domain: length (splitDomain domain) <= 2;
|
||||||
|
mkRootDomain = domain: concatStringsSep "." (shortenList 2 (splitDomain domain));
|
||||||
|
mkWildcardDomain = rootDomain: concatStringsSep "." ((singleton "*") ++ (splitDomain rootDomain));
|
||||||
|
mkHost = domain: if isRootDomain domain then domain else mkWildcardDomain (mkRootDomain domain);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue