4 let n = pkgs.lib.lists.foldr (x: acc: if pred x then acc + 1 else 0) 0 list;
5 in { fst = pkgs.lib.lists.take n list; snd = pkgs.lib.lists.drop n list; };
7 # Look for a index-state: field in the cabal.project file
8 parseIndexState = rawCabalProject:
10 indexState = pkgs.lib.lists.concatLists (
11 pkgs.lib.lists.filter (l: l != null)
12 (builtins.map (l: builtins.match "^index-state: *(.*)" l)
13 (pkgs.lib.splitString "\n" rawCabalProject)));
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)]
44 # Parse lines of a source-repository-package block
45 parseBlockLines = blockLines: (pkgs.lib.foldl' ({name, attrs}: s:
47 # Look for a new attribute name
48 pair = builtins.match "([^ :]*): *(.*)" s;
50 # Function to build the next parse state when the attribute name is known
51 nextState = name: value: {
53 # Support multi line attributes by appending the value to the named attribute
57 then attrs.${name} + " " + value
64 # First line of a new attribute
65 nextState (builtins.head pair) (builtins.elemAt pair 1)
68 then nextState name s # Append another line to the current attribute
69 else __trace "Expected attribute but found `${s}`" { inherit name attrs; }
70 ) { name = null; attrs = {}; } (stripComments (unindent blockLines))).attrs;
72 # Gets data for all the repositories to fetch
74 # --shar256: 003lm3pm0000hbfmii7xcdd9v20000flxf7gdl2pyxia7p014i8z
75 # will be trated like a field and returned here
76 # (used in call-cabal-project-to-nix.nix to create a fixed-output derivation)
77 extractRepoData = cabalProjectFileName: lookupSha256: repo: {
80 sha256 = repo."--sha256" or (lookupSha256 repo);
81 subdirs = if repo ? subdir
82 then pkgs.lib.filter (x: x != "") (pkgs.lib.splitString " " repo.subdir)
86 # Parse a source-repository-package and return data of `type: git` repositories
87 parseBlock = cabalProjectFileName: lookupSha256: block:
89 x = span (pkgs.lib.strings.hasPrefix " ") (pkgs.lib.splitString "\n" block);
90 attrs = parseBlockLines x.fst;
92 if attrs."type" or "" != "git"
95 otherText = "\nsource-repository-package\n" + block;
98 sourceRepo = extractRepoData cabalProjectFileName lookupSha256 attrs;
99 otherText = pkgs.lib.strings.concatStringsSep "\n" x.snd;
103 inherit parseIndexState parseBlockLines parseBlock;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list