@@ -14,11 +14,38 @@ let
1414 in
1515 pkgs.lib.lists.head (indexState ++ [ null ]);
1616
17+ # Remove the indentation of the first line from all the lines
18+ unindent = blockLines: (pkgs.lib.foldl' ({matchString, out}: s:
19+ let
20+ m = builtins.match matchString s;
21+ in
22+ if m != null
23+ then {
24+ matchString = "(${builtins.head m})(.*)";
25+ out = out ++ [(builtins.elemAt m 1)];
26+ }
27+ else {
28+ inherit matchString out;
29+ }
30+ ) { matchString = "( *)(.*)"; out = []; } blockLines).out;
31+
32+ # Strip comments except `--sha256`
33+ stripComments = blockLines: pkgs.lib.filter (s: s != "") (
34+ pkgs.lib.foldl' (out: s:
35+ let
36+ m = builtins.match "(.*)--.*" s;
37+ in
38+ if !(pkgs.lib.hasPrefix "--sha256" s) && m != null
39+ then out ++ [(builtins.head m)]
40+ else out ++ [s]
41+ ) [] blockLines
42+ );
43+
1744 # Parse lines of a source-repository-package block
1845 parseBlockLines = blockLines: (pkgs.lib.foldl' ({name, attrs}: s:
1946 let
2047 # Look for a new attribute name
21− pair = builtins.match " *([^:]*): *(.*)" s;
48+ pair = builtins.match "([^ :]*): *(.*)" s;
2249
2350 # Function to build the next parse state when the attribute name is known
2451 nextState = name: value: {
@@ -40,7 +67,7 @@ let
4067 if name != null
4168 then nextState name s # Append another line to the current attirbute
4269 else __trace "Expected attribute but found `${s}`" { inherit name attrs; }
43− ) { name = null; attrs = {}; } blockLines).attrs;
70+ ) { name = null; attrs = {}; } (stripComments (unindent blockLines))).attrs;
4471
4572 hashPath = path:
4673 builtins.readFile (pkgs.runCommand "hash-path" { preferLocalBuild = true; }