Skip to content

Instantly share code, notes, and snippets.

@offlinehacker
Created October 12, 2019 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save offlinehacker/36d90da265886ee80e4d16c972bb925a to your computer and use it in GitHub Desktop.
Save offlinehacker/36d90da265886ee80e4d16c972bb925a to your computer and use it in GitHub Desktop.
Reusable utility nix functions
{
removeAttrByPath = attrPath: attrs:
let
recurse = residualPath: currentPath: set:
let
# if on course continue recursion else just return value
g = name: value:
if name == lib.head residualPath
then recurse (lib.tail residualPath) (currentPath ++ [name]) value
else value;
# if current path is same prune path
f = name: _: currentPath ++ [name] != attrPath;
in lib.mapAttrs g (lib.filterAttrs f set);
in recurse attrPath [] attrs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment