-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.nix
31 lines (24 loc) · 1.2 KB
/
lib.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{ lib, ... }:
rec {
# List all item names with specified type under specified path
getDirContentByType =
type: path:
let
dirContent = if lib.pathIsDirectory path then builtins.readDir path else { };
in
builtins.filter (name: dirContent.${name} == type) (builtins.attrNames dirContent);
# Get all folder names under specified path
getFolderNames = getDirContentByType "directory";
# Get all folder full paths under specified path
getFolderPaths = path: builtins.map (x: path + "/${x}") (getFolderNames path);
# Get all regular file names under specified path
getRegularFileNames = getDirContentByType "regular";
# Get all regular file full paths under specified path
getRegularFilePaths = path: builtins.map (x: path + "/${x}") (getRegularFileNames path);
# Get all nix file names under specified path
getNixFileNames = path: builtins.filter (lib.hasSuffix ".nix") (getRegularFileNames path);
# Get all nix file names under specified path
getNixFileNamesWithoutExt = path: builtins.map (lib.removeSuffix ".nix") (getNixFileNames path);
# Get all nix file full paths under specified path
getNixFilePaths = path: builtins.map (x: path + "/${x}") (getNixFileNames path);
}