mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 06:39:14 +00:00
better clustering
This commit is contained in:
parent
f2cdc96007
commit
6dba1aaca8
3 changed files with 128 additions and 38 deletions
102
default.nix
102
default.nix
|
|
@ -16,6 +16,14 @@
|
|||
};
|
||||
};
|
||||
|
||||
packages = import ./nix/packages {inherit sources;};
|
||||
|
||||
#
|
||||
#
|
||||
# Module graph generation experiment below
|
||||
#
|
||||
#
|
||||
|
||||
inherit (nixosConfigurations.vanadium) options;
|
||||
|
||||
/*
|
||||
|
|
@ -27,21 +35,28 @@
|
|||
We could draw out file -> option, and cluster each option in a file rectangle
|
||||
*/
|
||||
|
||||
traceShowId = x: builtins.trace x x;
|
||||
|
||||
# Drop those that fail to eval
|
||||
filtered = let
|
||||
drop = path: {
|
||||
inherit path;
|
||||
update = _: {};
|
||||
};
|
||||
in
|
||||
lib.updateManyAttrsByPath
|
||||
(map drop [
|
||||
["_module"]
|
||||
["services" "immich"] # caused by option referencing a config value
|
||||
["services" "nagios"]
|
||||
["hardware" "nvidia"]
|
||||
])
|
||||
options;
|
||||
filtered =
|
||||
let
|
||||
drop = path: {
|
||||
inherit path;
|
||||
update = _: {};
|
||||
};
|
||||
in
|
||||
lib.updateManyAttrsByPath
|
||||
(map drop [
|
||||
["_module"]
|
||||
["services" "immich"] # caused by option referencing a config value
|
||||
["services" "nagios"]
|
||||
["hardware" "nvidia"]
|
||||
])
|
||||
# options
|
||||
# Use this for a smaller example
|
||||
# {inherit (options.programs) vim less;}
|
||||
{ inherit (options) programs; }
|
||||
;
|
||||
|
||||
# Transform each option to its path and call site
|
||||
mapped =
|
||||
|
|
@ -55,7 +70,9 @@
|
|||
_type = "result";
|
||||
optionPath = v.loc;
|
||||
definedBy = definedBy.value;
|
||||
declaredAt = map (x: x.file) v.declarationPositions;
|
||||
declaredAt =
|
||||
# There can only be one
|
||||
(builtins.head v.declarationPositions).file;
|
||||
}
|
||||
)
|
||||
filtered;
|
||||
|
|
@ -70,13 +87,62 @@
|
|||
|
||||
# Run `nix eval --json -f ./. 'asList' | jq >asList.json` to generate
|
||||
asList = let
|
||||
untag = map (lib.flip lib.removeAttrs ["_type"]);
|
||||
untag = lib.flip lib.removeAttrs ["_type"];
|
||||
in
|
||||
untag (
|
||||
map untag (
|
||||
attrValuesRecursiveCond
|
||||
(as: !(as ? _type && as._type == "result"))
|
||||
mapped
|
||||
);
|
||||
|
||||
packages = import ./nix/packages {inherit sources;};
|
||||
# TODO: Improve the granularity by checking the prefix
|
||||
#
|
||||
# Each attribute is a list of nodes in the same file
|
||||
clusterized =
|
||||
builtins.foldl' (
|
||||
acc: elem:
|
||||
acc
|
||||
// {
|
||||
${elem.declaredAt} =
|
||||
acc.${elem.declaredAt} or []
|
||||
++ [elem];
|
||||
}
|
||||
)
|
||||
{}
|
||||
asList;
|
||||
|
||||
subgraphs =
|
||||
lib.mapAttrsToList (
|
||||
declaredAt: elems: let
|
||||
entries =
|
||||
lib.concatMapStrings (
|
||||
elem:
|
||||
lib.concatMapStrings (
|
||||
def:
|
||||
lib.optionalString (
|
||||
def != elem.declaredAt # remove loops
|
||||
)
|
||||
''
|
||||
"${def}" -> "${builtins.concatStringsSep "." elem.optionPath}";
|
||||
''
|
||||
)
|
||||
elem.definedBy
|
||||
)
|
||||
elems;
|
||||
in ''
|
||||
subgraph "cluster_${declaredAt}" {
|
||||
${entries}
|
||||
label = "${declaredAt}";
|
||||
}
|
||||
''
|
||||
)
|
||||
clusterized;
|
||||
|
||||
graphvizOutput = ''
|
||||
digraph {
|
||||
// compound=true;
|
||||
rankdir="TB";
|
||||
${builtins.concatStringsSep "\n" subgraphs}
|
||||
}
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue