Repository navigation
Expand file tree
/
Copy pathpack.nix
More file actions
49 lines (46 loc) · 1.39 KB
/
Copy pathpack.nix
File metadata and controls
49 lines (46 loc) · 1.39 KB
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
45
46
47
48
49
{lib}: file: let
unquote = s: let
m = builtins.match ''"(.*)"'' s;
in
if m == null
then s
else lib.head m;
lines = lib.filter (l: builtins.match "[[:space:]]*(#.*)?" l == null) (lib.splitString "\n" (builtins.readFile file));
checked = line: value:
if (lib.hasPrefix "[" value && value != "[]") || lib.hasInfix " #" value || builtins.match ".*[[:space:]]" value != null
then throw "anikonistack: unsupported YAML in ${file}: ${line}"
else value;
step = acc: line: let
item = builtins.match "[[:space:]]+- (.*)" line;
pair = builtins.match "([A-Za-z0-9_-]+):[[:space:]]*(.*)" line;
in
if item != null && acc.current != null
then acc // {result = acc.result // {${acc.current} = acc.result.${acc.current} ++ [(unquote (checked line (lib.head item)))];};}
else if pair == null
then throw "anikonistack: unrecognised line in ${file}: ${line}"
else let
key = lib.elemAt pair 0;
value = checked line (lib.elemAt pair 1);
in
if value == ""
then {
current = key;
result = acc.result // {${key} = [];};
}
else {
current = null;
result =
acc.result
// {
${key} =
if value == "[]"
then []
else unquote value;
};
};
in
(lib.foldl' step {
current = null;
result = {};
}
lines).result