blob: 794d3e7c7b7afad9f9187256ba1315aacf438daf (
plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
|
{ lib, ... }:
let
inherit (builtins)
head
mapAttrs
match
readDir
;
inherit (lib)
mapAttrs'
filterAttrs
;
in
path: fn:
let
entries = readDir path;
# Get paths to directories
onlyDirs = filterAttrs (_name: type: type == "directory") entries;
dirPaths = mapAttrs (name: type: {
path = path + "/${name}";
inherit type;
}) onlyDirs;
# Get paths to nix files, where the name is the basename of the file without the .nix extension
nixPaths = removeAttrs (mapAttrs' (
name: type:
let
nixName = match "(.*)\\.nix" name;
in
{
name = if type == "directory" || nixName == null then "__junk" else (head nixName);
value = {
path = path + "/${name}";
type = type;
};
}
) entries) [ "__junk" ];
combined = dirPaths // nixPaths;
in
fn combined
|