lol
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 23.11-beta 57 lines 2.3 kB view raw
1let 2 lib = import ../../lib; 3 inherit (lib) 4 add attrNames elemAt foldl' genList length replaceStrings sort toLower trace; 5 6 maintainers = import ../maintainer-list.nix; 7 simplify = replaceStrings [ "-" "_" ] [ "" "" ]; 8 compare = a: b: simplify (toLower a) < simplify (toLower b); 9 namesSorted = 10 sort 11 (a: b: a.key < b.key) 12 (map 13 (n: let pos = builtins.unsafeGetAttrPos n maintainers; 14 in assert pos == null -> throw "maintainers entry ${n} is malformed"; 15 { name = n; line = pos.line; key = toLower (simplify n); }) 16 (attrNames maintainers)); 17 before = { name, line, key }: 18 foldl' 19 (acc: n: if n.key < key && (acc == null || n.key > acc.key) then n else acc) 20 null 21 namesSorted; 22 errors = foldl' add 0 23 (map 24 (i: let a = elemAt namesSorted i; 25 b = elemAt namesSorted (i + 1); 26 lim = let t = before a; in if t == null then "the initial {" else t.name; 27 in if a.line >= b.line 28 then trace 29 ("maintainer ${a.name} (line ${toString a.line}) should be listed " 30 + "after ${lim}, not after ${b.name} (line ${toString b.line})") 31 1 32 else 0) 33 (genList (i: i) (length namesSorted - 1))); 34in 35assert errors == 0; "all good!" 36 37# generate edit commands to sort the list. 38# may everything following the last current entry (closing } ff) in the wrong place 39# with lib; 40# concatStringsSep 41# "\n" 42# (let first = foldl' (acc: n: if n.line < acc then n.line else acc) 999999999 namesSorted; 43# commands = map 44# (i: let e = elemAt namesSorted i; 45# begin = foldl' 46# (acc: n: if n.line < e.line && n.line > acc then n.line else acc) 47# 1 48# namesSorted; 49# end = 50# foldl' (acc: n: if n.line > e.line && n.line < acc then n.line else acc) 51# 999999999 52# namesSorted; 53# in "${toString e.line},${toString (end - 1)} p") 54# (genList (i: i) (length namesSorted)); 55# in map 56# (c: "sed -ne '${c}' maintainers/maintainer-list.nix") 57# ([ "1,${toString (first - 1)} p" ] ++ commands))