modules(pihole-container): add options for configuring Pi-hole's FTLDNS component
This commit is contained in:
parent
d72b14f17b
commit
17f09210bc
2 changed files with 34 additions and 6 deletions
23
lib/util.nix
23
lib/util.nix
|
|
@ -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)
|
||||
;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue