2021-05-15 04:11:35 +03:00
|
|
|
let
|
2021-05-15 19:42:16 +03:00
|
|
|
inherit (builtins) isAttrs isList map any concatMap concatStringsSep listToAttrs genList;
|
2021-05-15 04:11:35 +03:00
|
|
|
|
|
|
|
mapAttrsToList = f: attrs: map (name: f name attrs.${name}) (builtins.attrNames attrs);
|
|
|
|
in
|
2022-07-30 12:42:09 +03:00
|
|
|
{
|
|
|
|
inherit mapAttrsToList;
|
2021-05-15 04:11:35 +03:00
|
|
|
|
2022-07-30 12:42:09 +03:00
|
|
|
recursiveAttrPaths = set: let
|
2021-05-15 04:11:35 +03:00
|
|
|
flattenIfHasList = x:
|
|
|
|
if (isList x) && (any isList x)
|
|
|
|
then concatMap flattenIfHasList x
|
2022-07-30 12:42:09 +03:00
|
|
|
else [x];
|
2021-05-15 04:11:35 +03:00
|
|
|
|
2022-07-30 12:42:09 +03:00
|
|
|
recurse = path: set: let
|
|
|
|
g = name: value:
|
|
|
|
if isAttrs value
|
|
|
|
then recurse (path ++ [name]) value
|
|
|
|
else path ++ [name];
|
|
|
|
in
|
2021-05-15 04:11:35 +03:00
|
|
|
mapAttrsToList g set;
|
|
|
|
in
|
2022-07-30 12:42:09 +03:00
|
|
|
flattenIfHasList (recurse [] set);
|
2021-05-15 04:11:35 +03:00
|
|
|
|
2022-07-30 12:42:09 +03:00
|
|
|
concatStrings = concatStringsSep "";
|
|
|
|
genAttrs = f: names:
|
|
|
|
listToAttrs (map (n: {
|
|
|
|
name = n;
|
|
|
|
value = f n;
|
|
|
|
})
|
|
|
|
names);
|
2021-05-15 19:42:16 +03:00
|
|
|
|
2022-07-30 12:42:09 +03:00
|
|
|
range = first: last:
|
|
|
|
if first > last
|
|
|
|
then []
|
|
|
|
else genList (n: first + n) (last - first + 1);
|
|
|
|
}
|
|
|
|
// builtins
|