{ lib, ... }: let inherit (lib) concatStringsSep foldl' groupBy unique ; duplicateUids = entries: let byUid = groupBy (entry: toString entry.value) entries; in foldl' ( acc: uid: let serviceNames = unique (map (entry: entry.entry) byUid.${uid}); in if builtins.length serviceNames > 1 then acc ++ [ { uid = lib.toInt uid; inherit serviceNames; } ] else acc ) [ ] (builtins.attrNames byUid); renderUidConflict = conflict: "${toString conflict.uid} is assigned to ${concatStringsSep ", " conflict.serviceNames}"; in { # Next stable UID: 20003 replicate = true; type = lib.types.ints.positive; validate = entries: let uidConflicts = duplicateUids entries; in [ { assertion = uidConflicts == [ ]; message = '' Duplicate stable UID allocation(s): ${concatStringsSep "\n" (map renderUidConflict uidConflicts)} ''; } ]; }