diff --git a/modules/system/meta/domains.nix b/modules/system/meta/domains.nix index 9789ee2..078f935 100644 --- a/modules/system/meta/domains.nix +++ b/modules/system/meta/domains.nix @@ -6,29 +6,6 @@ }: let cfg = config.meta.domains; - - duplicatedDomains = - self.nixosConfigurations - |> lib.mapAttrsToList (_: value: value.options.meta.domains.list.definitionsWithLocations) - |> lib.concatLists - |> lib.concatMap ( - entry: - map (domain: { - file = entry.file; - inherit domain; - }) entry.value - ) - |> lib.groupBy (entry: toString entry.domain) - |> lib.filterAttrs (domain: entries: lib.length entries > 1); - - errorMessage = - duplicatedDomains - |> lib.mapAttrsToList ( - domain: entries: - "Duplicate domain \"${domain}\" found in:\n" - + lib.concatMapStrings (entry: " - ${entry.file}\n") entries - ) - |> lib.concatStrings; in { options.meta.domains = { @@ -37,17 +14,51 @@ in default = [ ]; internal = true; }; + globalList = lib.mkOption { + type = lib.types.listOf lib.types.nonEmptyStr; + default = + self.nixosConfigurations + |> lib.mapAttrsToList (_: value: value.config.meta.domains.list) + |> lib.concatLists; + internal = true; + readOnly = true; + }; assertUnique = lib.mkEnableOption "" // { default = true; }; }; config = lib.mkIf cfg.assertUnique { - assertions = [ - { - assertion = duplicatedDomains == { }; - message = errorMessage; - } - ]; + assertions = + let + duplicateDomains = + self.nixosConfigurations + |> lib.mapAttrsToList (_: value: value.options.meta.domains.list.definitionsWithLocations) + |> lib.concatLists + |> lib.concatMap ( + entry: + map (domain: { + file = entry.file; + inherit domain; + }) entry.value + ) + |> lib.groupBy (entry: toString entry.domain) + |> lib.filterAttrs (domain: entries: lib.length entries > 1); + + errorMessage = + duplicateDomains + |> lib.mapAttrsToList ( + domain: entries: + "Duplicate domain \"${domain}\" found in:\n" + + lib.concatMapStrings (entry: " - ${entry.file}\n") entries + ) + |> lib.concatStrings; + in + [ + { + assertion = duplicateDomains == { }; + message = errorMessage; + } + ]; }; } diff --git a/modules/system/meta/ports.nix b/modules/system/meta/ports.nix index 138fea7..4c7fde1 100644 --- a/modules/system/meta/ports.nix +++ b/modules/system/meta/ports.nix @@ -6,26 +6,6 @@ }: let cfg = config.meta.ports; - - duplicatedPorts = - options.meta.ports.list.definitionsWithLocations - |> lib.concatMap ( - entry: - map (port: { - file = entry.file; - inherit port; - }) entry.value - ) - |> lib.groupBy (entry: toString entry.port) - |> lib.filterAttrs (port: entries: lib.length entries > 1); - - errorMessage = - duplicatedPorts - |> lib.mapAttrsToList ( - port: entries: - "Duplicate port ${port} found in:\n" + lib.concatMapStrings (entry: " - ${entry.file}\n") entries - ) - |> lib.concatStrings; in { options.meta.ports = { @@ -40,11 +20,33 @@ in }; config = lib.mkIf cfg.assertUnique { - assertions = [ - { - assertion = duplicatedPorts == { }; - message = errorMessage; - } - ]; + assertions = + let + duplicatePorts = + options.meta.ports.list.definitionsWithLocations + |> lib.concatMap ( + entry: + map (port: { + inherit (entry) file; + inherit port; + }) entry.value + ) + |> lib.groupBy (entry: toString entry.port) + |> lib.filterAttrs (port: entries: lib.length entries > 1); + + errorMessage = + duplicatePorts + |> lib.mapAttrsToList ( + port: entries: + "Duplicate port ${port} found in:\n" + lib.concatMapStrings (entry: " - ${entry.file}\n") entries + ) + |> lib.concatStrings; + in + [ + { + assertion = duplicatePorts == { }; + message = errorMessage; + } + ]; }; }