summaryrefslogtreecommitdiffstats
path: root/krebs/4lib/dns.nix
blob: b2cf3c24ccd3ef61eba95f7152fb3e0d8edb77ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{ 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));
}