refactor(registry): add stable uid registry
This commit was merged in pull request #64.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
{ lib }:
|
||||
{ lib, ... }:
|
||||
{
|
||||
type = lib.types.str;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{ lib }:
|
||||
{ lib, ... }:
|
||||
{
|
||||
type = lib.types.submodule {
|
||||
options = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{ lib }:
|
||||
{ lib, ... }:
|
||||
let
|
||||
entryType = lib.types.submodule {
|
||||
options = {
|
||||
|
||||
31
registry/stable-uid.nix
Normal file
31
registry/stable-uid.nix
Normal file
@@ -0,0 +1,31 @@
|
||||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib)
|
||||
filterAttrs
|
||||
groupBy
|
||||
mapAttrs
|
||||
unique
|
||||
;
|
||||
|
||||
serviceNamesByUid = entries:
|
||||
mapAttrs (_uid: uidEntries: unique (map (entry: entry.entry) uidEntries)) (
|
||||
groupBy (entry: toString entry.value) entries
|
||||
);
|
||||
|
||||
duplicateUids = entries:
|
||||
filterAttrs (_uid: serviceNames: builtins.length serviceNames > 1) (serviceNamesByUid entries);
|
||||
|
||||
in
|
||||
{
|
||||
# Next stable UID: 20003
|
||||
replicate = true;
|
||||
|
||||
type = lib.types.ints.positive;
|
||||
|
||||
validate = entries: [
|
||||
{
|
||||
assertion = duplicateUids entries == { };
|
||||
message = "Stable UID allocations must be unique.";
|
||||
}
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user