Something went wrong. Try again.
A Nordic stronghold for declarative computing.
flakes nix nixos nix-darwin
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354let inherit (builtins) readDir attrNames match concatLists any substring stringLength elem ;
hasPrefix = prefix: str: substring 0 (stringLength prefix) str == prefix;
matchesAny = patterns: name: any (pattern: match pattern name != null) patterns;
in{ path # dir to walk, include ? [ ".*\\.nix" ] # regexes; file kept if it matches ANY, exclude ? [ "flake.nix" "flake.lock" ] # exact names to always skip, ignoreUnderscore ? true # skip files/dirs starting with "_"}:
let validName = name: !(ignoreUnderscore && hasPrefix "_" name) && !(elem name exclude);
walk = dir: let entries = readDir dir; names = attrNames entries; in concatLists (map (name: let type = entries.${name}; p = dir + "/${name}"; in if !(validName name) then [ ] else if type == "directory" then walk p else if type == "regular" && matchesAny include name then [ p ] else [ ] ) names);
inwalk path