krebs.dns.providers: attrsOf unspecified -> attrsOf str
This commit is contained in:
parent
67e5fddc0b
commit
de5de37a12
@ -43,9 +43,7 @@ let
|
|||||||
|
|
||||||
dns = {
|
dns = {
|
||||||
providers = mkOption {
|
providers = mkOption {
|
||||||
# TODO with types; tree dns.label dns.provider, so we can merge.
|
type = with types; attrsOf str;
|
||||||
# Currently providers can only be merged if aliases occur just once.
|
|
||||||
type = with types; attrsOf unspecified;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -95,7 +93,7 @@ let
|
|||||||
{ krebs = import ./tv { inherit config lib; }; }
|
{ krebs = import ./tv { inherit config lib; }; }
|
||||||
{
|
{
|
||||||
krebs.dns.providers = {
|
krebs.dns.providers = {
|
||||||
de.krebsco = "zones";
|
"krebsco.de" = "zones";
|
||||||
gg23 = "hosts";
|
gg23 = "hosts";
|
||||||
shack = "hosts";
|
shack = "hosts";
|
||||||
i = "hosts";
|
i = "hosts";
|
||||||
@ -116,13 +114,15 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.extraHosts = concatStringsSep "\n" (flatten (
|
networking.extraHosts = let
|
||||||
|
domains = attrNames (filterAttrs (_: eq "hosts") cfg.dns.providers);
|
||||||
|
check = hostname: any (domain: hasSuffix ".${domain}" hostname) domains;
|
||||||
|
in concatStringsSep "\n" (flatten (
|
||||||
mapAttrsToList (hostname: host:
|
mapAttrsToList (hostname: host:
|
||||||
mapAttrsToList (netname: net:
|
mapAttrsToList (netname: net:
|
||||||
let
|
let
|
||||||
aliases = longs ++ shorts;
|
aliases = longs ++ shorts;
|
||||||
providers = dns.split-by-provider net.aliases cfg.dns.providers;
|
longs = filter check net.aliases;
|
||||||
longs = providers.hosts;
|
|
||||||
shorts = let s = ".${cfg.search-domain}"; in
|
shorts = let s = ".${cfg.search-domain}"; in
|
||||||
map (removeSuffix s) (filter (hasSuffix s) longs);
|
map (removeSuffix s) (filter (hasSuffix s) longs);
|
||||||
in
|
in
|
||||||
|
@ -4,7 +4,7 @@ with config.krebs.lib;
|
|||||||
|
|
||||||
{
|
{
|
||||||
dns.providers = {
|
dns.providers = {
|
||||||
de.viljetic = "regfish";
|
"viljetic.de" = "regfish";
|
||||||
};
|
};
|
||||||
hosts = mapAttrs (_: setAttr "owner" config.krebs.users.tv) {
|
hosts = mapAttrs (_: setAttr "owner" config.krebs.users.tv) {
|
||||||
cd = rec {
|
cd = rec {
|
||||||
|
@ -22,10 +22,8 @@ let out = rec {
|
|||||||
|
|
||||||
dir.has-default-nix = path: pathExists (path + "/default.nix");
|
dir.has-default-nix = path: pathExists (path + "/default.nix");
|
||||||
|
|
||||||
dns = import ./dns.nix { inherit lib; };
|
|
||||||
genid = import ./genid.nix { lib = lib // out; };
|
genid = import ./genid.nix { lib = lib // out; };
|
||||||
git = import ./git.nix { lib = lib // out; };
|
git = import ./git.nix { lib = lib // out; };
|
||||||
listset = import ./listset.nix { inherit lib; };
|
|
||||||
shell = import ./shell.nix { inherit lib; };
|
shell = import ./shell.nix { inherit lib; };
|
||||||
tree = import ./tree.nix { inherit lib; };
|
tree = import ./tree.nix { inherit lib; };
|
||||||
|
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
{ lib, ... }:
|
|
||||||
|
|
||||||
let
|
|
||||||
listset = import ./listset.nix { inherit lib; };
|
|
||||||
in
|
|
||||||
|
|
||||||
with builtins;
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
rec {
|
|
||||||
# label = string
|
|
||||||
|
|
||||||
# TODO does it make sense to have alias = list label?
|
|
||||||
|
|
||||||
# split-by-provider :
|
|
||||||
# [[label]] -> tree label provider -> listset provider alias
|
|
||||||
split-by-provider = as: providers:
|
|
||||||
foldl (m: a: listset.insert (provider-of a providers) a m) {} as;
|
|
||||||
|
|
||||||
# provider-of : alias -> tree label provider -> provider
|
|
||||||
# Note that we cannot use tree.get here, because path can be longer
|
|
||||||
# than the tree depth.
|
|
||||||
provider-of = a:
|
|
||||||
let
|
|
||||||
go = path: tree:
|
|
||||||
if typeOf tree == "string"
|
|
||||||
then tree
|
|
||||||
else go (tail path) tree.${head path};
|
|
||||||
in
|
|
||||||
go (reverseList (splitString "." a));
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
{ lib, ... }:
|
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
rec {
|
|
||||||
# listset k v = set k [v]
|
|
||||||
|
|
||||||
# insert : k -> v -> listset k v -> listset k v
|
|
||||||
insert = name: value: set:
|
|
||||||
set // { ${name} = set.${name} or [] ++ [value]; };
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user