refactor(nix/lib): rewrite recurseDir
to leverage pipe operators
Some checks failed
Check Formatting of Files / Check-Formatting (push) Failing after 32s
Some checks failed
Check Formatting of Files / Check-Formatting (push) Failing after 32s
This commit is contained in:
parent
b975022f17
commit
11ad7c3991
@ -3,28 +3,18 @@
|
|||||||
lib ? (import <nixpkgs> { }).lib,
|
lib ? (import <nixpkgs> { }).lib,
|
||||||
}:
|
}:
|
||||||
rec {
|
rec {
|
||||||
hasSuffix =
|
|
||||||
suffix: string:
|
|
||||||
let
|
|
||||||
lenSuffix = builtins.stringLength suffix;
|
|
||||||
lenString = builtins.stringLength string;
|
|
||||||
in
|
|
||||||
(lenString >= lenSuffix && (builtins.substring (lenString - lenSuffix) lenString string) == suffix);
|
|
||||||
recurseDir =
|
recurseDir =
|
||||||
dir:
|
dir:
|
||||||
let
|
builtins.readDir dir
|
||||||
dirContents = builtins.readDir dir;
|
|> lib.attrsets.mapAttrs' (
|
||||||
in
|
fEntry: fType: lib.attrsets.nameValuePair (builtins.toString (dir + "/${fEntry}")) fType
|
||||||
(builtins.concatMap (
|
)
|
||||||
dirItem:
|
|> lib.attrsets.mapAttrsToList (
|
||||||
let
|
fEntry: fType: if fType == "directory" then (recurseDir "${fEntry}") else "${fEntry}"
|
||||||
itemType = builtins.getAttr dirItem dirContents;
|
)
|
||||||
itemPath = dir + "/${dirItem}";
|
|> lib.lists.flatten;
|
||||||
in
|
|
||||||
if itemType == "directory" then (recurseDir itemPath) else [ itemPath ]
|
|
||||||
) (builtins.attrNames dirContents));
|
|
||||||
recurseFilesInDir =
|
recurseFilesInDir =
|
||||||
dir: suffix: (builtins.filter (file: hasSuffix "${suffix}" file) (recurseDir dir));
|
dir: suffix: (builtins.filter (file: lib.strings.hasSuffix "${suffix}" file) (recurseDir dir));
|
||||||
recurseFilesInDirs =
|
recurseFilesInDirs =
|
||||||
dirs: suffix: (builtins.concatMap (dir: (recurseFilesInDir dir "${suffix}")) dirs);
|
dirs: suffix: (builtins.concatMap (dir: (recurseFilesInDir dir "${suffix}")) dirs);
|
||||||
# Full credit to https://stackoverflow.com/questions/54504685/nix-function-to-merge-attributes-records-recursively-and-concatenate-arrays/54505212#54505212
|
# Full credit to https://stackoverflow.com/questions/54504685/nix-function-to-merge-attributes-records-recursively-and-concatenate-arrays/54505212#54505212
|
||||||
|
Loading…
Reference in New Issue
Block a user