rix101/lib/helpers.nix
reo101 e8e005029d chore(flake): rename lib -> helpers
Prevents name clashing with `nixpkgs.lib`
2022-11-28 00:08:48 +02:00

36 lines
775 B
Nix

{ lib, ... }:
let
inherit (lib) mapAttrs;
inherit (lib.attrsets) filterAttrs;
in
rec {
recurseDir = dir:
mapAttrs
(file: type:
if type == "directory"
then recurseDir "${dir}/${file}"
else type
)
(builtins.readDir dir);
# VVV - Implying `attrs` is the output of `recurseDir` - VVV
hasFiles = files: attrs:
builtins.all
(b: b)
(builtins.map
(file:
builtins.hasAttr file attrs &&
builtins.getAttr file attrs == "regular")
files);
hasDirectories = directories: attrs:
builtins.all
(b: b)
(builtins.map
(directory:
builtins.hasAttr directory attrs &&
builtins.getAttr directory attrs == "set")
directories);
}