refactor(registry): compose stable uid validation
This commit is contained in:
@@ -1,28 +1,19 @@
|
||||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib)
|
||||
foldl'
|
||||
filterAttrs
|
||||
groupBy
|
||||
mapAttrs
|
||||
unique
|
||||
;
|
||||
|
||||
serviceNamesByUid = entries:
|
||||
mapAttrs (_uid: uidEntries: unique (map (entry: entry.entry) uidEntries)) (
|
||||
groupBy (entry: toString entry.value) entries
|
||||
);
|
||||
|
||||
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);
|
||||
filterAttrs (_uid: serviceNames: builtins.length serviceNames > 1) (serviceNamesByUid entries);
|
||||
|
||||
in
|
||||
{
|
||||
@@ -37,7 +28,7 @@ in
|
||||
in
|
||||
[
|
||||
{
|
||||
assertion = uidConflicts == [ ];
|
||||
assertion = uidConflicts == { };
|
||||
message = "Stable UID allocations must be unique.";
|
||||
}
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user