This repository has been archived on 2026-08-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
dotfiles/registry/stable-uid.nix

45 lines
801 B
Nix

{ lib, ... }:
let
inherit (lib)
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);
in
{
# Next stable UID: 20003
replicate = true;
type = lib.types.ints.positive;
validate = entries:
let
uidConflicts = duplicateUids entries;
in
[
{
assertion = uidConflicts == [ ];
message = "Stable UID allocations must be unique.";
}
];
}