@@ -14,11 +14,38 @@ let
15 pkgs.lib.lists.head (indexState ++ [ null ]);
15 pkgs.lib.lists.head (indexState ++ [ null ]);
17+ # Remove the indentation of the first line from all the lines
18+ unindent = blockLines: (pkgs.lib.foldl' ({matchString, out}: s:
20+ m = builtins.match matchString s;
24+ matchString = "(${builtins.head m})(.*)";
25+ out = out ++ [(builtins.elemAt m 1)];
28+ inherit matchString out;
30+ ) { matchString = "( *)(.*)"; out = []; } blockLines).out;
32+ # Strip comments except `--sha256`
33+ stripComments = blockLines: pkgs.lib.filter (s: s != "") (
34+ pkgs.lib.foldl' (out: s:
36+ m = builtins.match "(.*)--.*" s;
38+ if !(pkgs.lib.hasPrefix "--sha256" s) && m != null
39+ then out ++ [(builtins.head m)]
17 # Parse lines of a source-repository-package block
44 # Parse lines of a source-repository-package block
18 parseBlockLines = blockLines: (pkgs.lib.foldl' ({name, attrs}: s:
45 parseBlockLines = blockLines: (pkgs.lib.foldl' ({name, attrs}: s:
20 # Look for a new attribute name
47 # Look for a new attribute name
21− pair = builtins.match " *([^:]*): *(.*)" s;
48+ pair = builtins.match "([^ :]*): *(.*)" s;
23 # Function to build the next parse state when the attribute name is known
50 # Function to build the next parse state when the attribute name is known
24 nextState = name: value: {
51 nextState = name: value: {
@@ -40,7 +67,7 @@ let
40 if name != null
67 if name != null
41 then nextState name s # Append another line to the current attirbute
68 then nextState name s # Append another line to the current attirbute
42 else __trace "Expected attribute but found `${s}`" { inherit name attrs; }
69 else __trace "Expected attribute but found `${s}`" { inherit name attrs; }
43− ) { name = null; attrs = {}; } blockLines).attrs;
70+ ) { name = null; attrs = {}; } (stripComments (unindent blockLines))).attrs;
45 hashPath = path:
72 hashPath = path:
46 builtins.readFile (pkgs.runCommand "hash-path" { preferLocalBuild = true; }
73 builtins.readFile (pkgs.runCommand "hash-path" { preferLocalBuild = true; }