diff --git a/flake.nix b/flake.nix index 50153e1..fbe630d 100644 --- a/flake.nix +++ b/flake.nix @@ -9,6 +9,7 @@ outputs = { self, nixpkgs, flake-utils }: with flake-utils.lib; eachSystem (with system; [ x86_64-linux aarch64-linux ]) (curSystem: let + util = import ./lib/util.nix; pkgs = nixpkgs.legacyPackages.${curSystem}; imageName = "pihole/pihole"; diff --git a/lib/util.nix b/lib/util.nix new file mode 100644 index 0000000..ee4b79c --- /dev/null +++ b/lib/util.nix @@ -0,0 +1,22 @@ +{ + collectAttrFragments = predicate: attrs: with builtins; let + _collectAttrFragments = attrs: + concatMap (key: _collectAttrFragmentsBelowKey key attrs.${key}) (attrNames attrs) + ; + _collectAttrFragmentsBelowKey = key: value: + if predicate value then [ [key] ] + else if isAttrs value then + map (fragment: [key] ++ fragment) (_collectAttrFragments value) + else [ ] + ; + in _collectAttrFragments attrs + ; + + accessValueOfFragment = attrs: fragment: with builtins; let + _accessValueOfFragment = value: fragment: + if fragment == [] then value + else _accessValueOfFragment (value.${head fragment}) (tail fragment) + ; + in _accessValueOfFragment attrs fragment + ; +}