refactor: move support functions to ./lib; change piholeConfiguration option to piholeConfig
The first part of the refactor simplifies the logic in the module and hides functions which are only used to extract container env vars. Second the option renaming to piholeConfig unifies the naming with the hostConfig option.
This commit is contained in:
parent
f734aea139
commit
c536fb7293
4 changed files with 73 additions and 63 deletions
32
lib/util.nix
32
lib/util.nix
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
collectAttrFragments = predicate: attrs: with builtins; let
|
||||
with builtins; let
|
||||
collectAttrFragments = predicate: attrs: let
|
||||
_collectAttrFragments = attrs:
|
||||
concatMap (key: _collectAttrFragmentsBelowKey key attrs.${key}) (attrNames attrs)
|
||||
;
|
||||
|
@ -12,7 +12,7 @@
|
|||
in _collectAttrFragments attrs
|
||||
;
|
||||
|
||||
accessValueOfFragment = attrs: fragment: with builtins; let
|
||||
accessValueOfFragment = attrs: fragment: let
|
||||
_accessValueOfFragment = value: fragment:
|
||||
if fragment == [] then value
|
||||
else _accessValueOfFragment (value.${head fragment}) (tail fragment)
|
||||
|
@ -20,8 +20,26 @@
|
|||
in _accessValueOfFragment attrs fragment
|
||||
;
|
||||
|
||||
toEnvValue = value: with builtins;
|
||||
if isBool value then (if value then "true" else "false")
|
||||
else if isList value then "[${concatStringSep ";" value}]"
|
||||
else value;
|
||||
toEnvValue = value:
|
||||
if isBool value then (if value then "true" else "false")
|
||||
else if isList value then "[${concatStringSep ";" value}]"
|
||||
else value
|
||||
;
|
||||
|
||||
in {
|
||||
extractContainerEnvVars = piholeOptionDeclarations: piholeOptionDefinitions: let
|
||||
_opt = piholeOptionDeclarations;
|
||||
_cfg = piholeOptionDefinitions;
|
||||
|
||||
_envVarFragments = collectAttrFragments (value: isAttrs value && value ? "envVar") _opt.piholeConfig;
|
||||
in filter
|
||||
(envVar: envVar.value != null)
|
||||
(map
|
||||
(fragment: {
|
||||
name = getAttr "envVar" (accessValueOfFragment _opt.piholeConfig fragment);
|
||||
value = toEnvValue (accessValueOfFragment _cfg.piholeConfig fragment);
|
||||
})
|
||||
_envVarFragments
|
||||
)
|
||||
;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue