diff --git a/topology/options/interfaces.nix b/topology/options/interfaces.nix index d3e265d..93fdf88 100644 --- a/topology/options/interfaces.nix +++ b/topology/options/interfaces.nix @@ -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})" + ) + ) + )); }; } diff --git a/topology/topology/default.nix b/topology/topology/default.nix index 8a014b2..709ef47 100644 --- a/topology/topology/default.nix +++ b/topology/topology/default.nix @@ -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"]; diff --git a/topology/topology/renderers/elk/default.nix b/topology/topology/renderers/elk/default.nix index 00d820b..65d5cda 100644 --- a/topology/topology/renderers/elk/default.nix +++ b/topology/topology/renderers/elk/default.nix @@ -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 = {