mirror of
https://github.com/oddlama/nix-config.git
synced 2025-10-10 23:00:39 +02:00
feat(topology): add warning when connecting different networks
This commit is contained in:
parent
59ca21850b
commit
65f1fc4bd7
3 changed files with 33 additions and 2 deletions
|
@ -11,6 +11,7 @@ f: {
|
||||||
mkDefault
|
mkDefault
|
||||||
mkIf
|
mkIf
|
||||||
mkOption
|
mkOption
|
||||||
|
optional
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
in
|
in
|
||||||
|
@ -124,5 +125,19 @@ in
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
warnings = flatten (flip map (attrValues config.nodes) (
|
||||||
|
node:
|
||||||
|
flip map (attrValues node.interfaces) (
|
||||||
|
interface:
|
||||||
|
flip map interface.physicalConnections (
|
||||||
|
physicalConnection: let
|
||||||
|
otherNetwork = config.nodes.${physicalConnection.node}.interfaces.${physicalConnection.interface}.network or null;
|
||||||
|
in
|
||||||
|
optional (interface.network != null && otherNetwork != null && interface.network != otherNetwork)
|
||||||
|
"topology: The interface nodes.${node.id}.interfaces.${interface.id} is associated with the network (${interface.network}), but also has a physicalConnection to nodes.${physicalConnection.node}.interfaces.${physicalConnection.interface} which is associated to a different network (${otherNetwork})"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
inherit
|
inherit
|
||||||
(lib)
|
(lib)
|
||||||
attrNames
|
attrNames
|
||||||
|
concatLines
|
||||||
concatLists
|
concatLists
|
||||||
concatStringsSep
|
concatStringsSep
|
||||||
filter
|
filter
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
mkMerge
|
mkMerge
|
||||||
mkOption
|
mkOption
|
||||||
types
|
types
|
||||||
|
warnIf
|
||||||
;
|
;
|
||||||
|
|
||||||
availableRenderers = attrNames (filterAttrs (_: v: v == "directory") (builtins.readDir ./renderers));
|
availableRenderers = attrNames (filterAttrs (_: v: v == "directory") (builtins.readDir ./renderers));
|
||||||
|
@ -94,6 +96,17 @@ in {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
warnings = mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = [];
|
||||||
|
example = ["This is deprecated for that reason"];
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
This option allows modules to show warnings to users during
|
||||||
|
the evaluation of the topology configuration.
|
||||||
|
'';
|
||||||
|
type = types.listOf types.str;
|
||||||
|
};
|
||||||
|
|
||||||
topology.isMainModule = mkOption {
|
topology.isMainModule = mkOption {
|
||||||
description = "Whether this is the toplevel topology module.";
|
description = "Whether this is the toplevel topology module.";
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -120,7 +133,10 @@ in {
|
||||||
in
|
in
|
||||||
if failedAssertions != []
|
if failedAssertions != []
|
||||||
then throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
|
then throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
|
||||||
else mkIf (config.renderer != null) (mkDefault config.renderers.${config.renderer}.output);
|
else
|
||||||
|
warnIf (config.warnings != [])
|
||||||
|
(concatLines (["The following warnings were raised during evaluation:"] ++ config.warnings))
|
||||||
|
(mkIf (config.renderer != null) (mkDefault config.renderers.${config.renderer}.output));
|
||||||
|
|
||||||
nodes = aggregate ["nodes"];
|
nodes = aggregate ["nodes"];
|
||||||
networks = aggregate ["networks"];
|
networks = aggregate ["networks"];
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
|
|
||||||
mkLabel = text: scale: extraStyle: {
|
mkLabel = text: scale: extraStyle: {
|
||||||
height = scale * 12;
|
height = scale * 12;
|
||||||
width = scale * 7.3 * (stringLength text);
|
width = scale * 7.2 * (stringLength text);
|
||||||
inherit text;
|
inherit text;
|
||||||
style =
|
style =
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue