1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-10 14:50:40 +02:00

feat(topology): add warning when connecting different networks

This commit is contained in:
oddlama 2024-03-29 23:54:47 +01:00
parent 59ca21850b
commit 65f1fc4bd7
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
3 changed files with 33 additions and 2 deletions

View file

@ -11,6 +11,7 @@ f: {
mkDefault
mkIf
mkOption
optional
types
;
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})"
)
)
));
};
}

View file

@ -6,6 +6,7 @@
inherit
(lib)
attrNames
concatLines
concatLists
concatStringsSep
filter
@ -19,6 +20,7 @@
mkMerge
mkOption
types
warnIf
;
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 {
description = "Whether this is the toplevel topology module.";
readOnly = true;
@ -120,7 +133,10 @@ in {
in
if 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"];
networks = aggregate ["networks"];

View file

@ -66,7 +66,7 @@
mkLabel = text: scale: extraStyle: {
height = scale * 12;
width = scale * 7.3 * (stringLength text);
width = scale * 7.2 * (stringLength text);
inherit text;
style =
{