Created
August 21, 2022 01:27
-
-
Save danielphan2003/5aae67b9ad06c2f5c05d378bf0a2e563 to your computer and use it in GitHub Desktop.
Revisions
-
danielphan2003 created this gist
Aug 21, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ {inputs,cell}: { /* A function that split namespaces by a separator. Example: ```nix # src { packagesA_helper1 = ...; packagesA_helper2 = ...; packagesB_helper1 = ...; } # splitNamespaceSep "_" src { packagesA = { helper1 = ...; helper2 = ...; }; packagesB = { helper1 = ...; }; } */ splitNamespaceSep = sep: src: let namespaces = l.foldl' (all: ns: let matches = l.splitString sep ns; namespace = l.head matches; pname = l.last matches; attrs = if l.length matches == 2 then { "${pname}" = l.getAttrFromPath [ns] src; } else cell.lib.splitNamespaceSep sep (l.mapAttrs' (name: l.nameValuePair (l.removePrefix "${namespace}." name) ) src) ; in l.recursiveUpdate all { "${namespace}" = attrs; }) {} (l.attrNames src) ; in namespaces ; }