2024-03-14 03:37:02 -05:00
# Some of these functions were taken from https://github.com/NixOS/nixpkgs/blob/master/lib/
2024-04-19 22:27:46 -05:00
{
lib ? ( import <nixpkgs> { } ) . lib ,
} :
rec {
recurseDir =
dir :
2024-11-06 17:29:36 -06:00
builtins . readDir dir
| > lib . attrsets . mapAttrs' (
fEntry : fType : lib . attrsets . nameValuePair ( builtins . toString ( dir + " / ${ fEntry } " ) ) fType
)
| > lib . attrsets . mapAttrsToList (
fEntry : fType : if fType == " d i r e c t o r y " then ( recurseDir " ${ fEntry } " ) else " ${ fEntry } "
)
| > lib . lists . flatten ;
2024-04-19 22:27:46 -05:00
recurseFilesInDir =
2024-11-06 17:29:36 -06:00
dir : suffix : ( builtins . filter ( file : lib . strings . hasSuffix " ${ suffix } " file ) ( recurseDir dir ) ) ;
2024-04-19 22:27:46 -05:00
recurseFilesInDirs =
dirs : suffix : ( builtins . concatMap ( dir : ( recurseFilesInDir dir " ${ suffix } " ) ) dirs ) ;
2024-03-14 03:37:02 -05:00
# Full credit to https://stackoverflow.com/questions/54504685/nix-function-to-merge-attributes-records-recursively-and-concatenate-arrays/54505212#54505212
2024-04-19 22:27:46 -05:00
recursiveMerge =
attrList :
2024-03-14 03:37:02 -05:00
let
2024-04-19 22:27:46 -05:00
f =
attrPath :
lib . zipAttrsWith (
n : values :
2024-03-16 13:01:28 -05:00
if lib . tail values == [ ] then
lib . head values
else if lib . all builtins . isList values then
lib . unique ( lib . concatLists values )
else if lib . all builtins . isAttrs values then
f ( attrPath ++ [ n ] ) values
else
2024-04-19 22:27:46 -05:00
lib . last values
) ;
in
f [ ] attrList ;
2024-03-14 03:37:02 -05:00
}