modules(pihole-container): add options for configuring Pi-hole's FTLDNS component

This commit is contained in:
Christopher Bacher 2022-10-31 01:13:22 +01:00
parent d72b14f17b
commit 17f09210bc
2 changed files with 34 additions and 6 deletions

View file

@ -1,12 +1,14 @@
with builtins; let
collectAttrFragments = predicate: attrs: let
collectAttrFragments = successPredicate: stopPredicate: attrs: let
_collectAttrFragments = attrs:
concatMap (key: _collectAttrFragmentsBelowKey key attrs.${key}) (attrNames attrs)
;
_collectAttrFragmentsBelowKey = key: value:
if predicate value then [ [key] ]
if successPredicate value then [ [key] ]
else if stopPredicate value then [ ]
else if isAttrs value then
map (fragment: [key] ++ fragment) (_collectAttrFragments value)
map (fragment: if length fragment > 0 then [key] ++ fragment else [ ]) (_collectAttrFragments value)
else [ ]
;
in _collectAttrFragments attrs
@ -31,7 +33,10 @@ in {
_opt = piholeOptionDeclarations;
_cfg = piholeOptionDefinitions;
_envVarFragments = collectAttrFragments (value: isAttrs value && value ? "envVar") _opt.piholeConfig;
_envVarFragments = collectAttrFragments
(value: isAttrs value && value ? "envVar")
(value: isAttrs value && value._type or "" == "option")
_opt.piholeConfig;
in filter
(envVar: envVar.value != null)
(map
@ -42,4 +47,14 @@ in {
_envVarFragments
)
;
extractContainerFTLEnvVars = piholeOptionDefinitions: let
_ftl = piholeOptionDefinitions.piholeConfig.ftl;
in map
(name: {
name = "FTL_${name}";
value = _ftl.${name};
})
(attrNames _ftl)
;
}