-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputSorter.nix
More file actions
66 lines (58 loc) · 1.29 KB
/
inputSorter.nix
File metadata and controls
66 lines (58 loc) · 1.29 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# TODO export as flake-parts module
{
flake,
lib,
...
}:
let
inherit (builtins)
attrNames
attrValues
concatLists
elem
filter
import
length
mapAttrs
;
inherit (lib.attrsets) genAttrs;
inherit (lib.lists) sort uniqueStrings;
inherit (lib.trivial) flip pipe;
in
rec {
orderedInputs = pipe flake.inputs [
attrNames
(sort (a: b: a < b))
(sort sortHelper)
];
sortHelper =
a: b:
let
bIsDependent = elem a recursiveFollowings.${b};
in
(recursiveFollowingCount.${a} < recursiveFollowingCount.${b}) || bIsDependent;
recursiveFollowingCount = mapAttrs (_: length) recursiveFollowings;
recursiveFollowings = pipe directFollowings [
attrNames
(flip genAttrs (
input:
let
following = directFollowings.${input};
followeds = map (followed: recursiveFollowings.${followed}) following;
in
uniqueStrings (following ++ concatLists followeds)
))
];
directFollowings = getAllFollowings flake;
getAllFollowings = flip pipe [
(flake: import "${flake}/flake.nix")
(raw: raw.inputs or { })
(mapAttrs (_: getFollowing))
];
getFollowing = flip pipe [
(inputDecl: inputDecl.inputs or { })
attrValues
(filter (i: i ? follows))
(map (i: i.follows))
];
}