refactor(dotfiles): remove registry replication #121

Merged
alexion merged 1 commits from refactor/inline-registry-join into main 2026-10-01 21:51:35 -04:00
5 changed files with 25 additions and 105 deletions

View File

@@ -13,7 +13,6 @@ let
in in
{ {
# Next stable UID: 20005 # Next stable UID: 20005
replicate = true;
type = lib.types.ints.positive; type = lib.types.ints.positive;

View File

@@ -127,9 +127,8 @@ Review Nix files in entrypoint order:
- [x] `src/flake/apps.nix` - [x] `src/flake/apps.nix`
- [x] `src/dotfiles/default.nix` - [x] `src/dotfiles/default.nix`
- [x] `src/dotfiles/util.nix` - [x] `src/dotfiles/util.nix`
- [ ] `src/dotfiles/registry.nix` - [x] `src/dotfiles/registry.nix`
- [ ] `src/dotfiles/registry/schema.nix` - [x] `src/dotfiles/registry/schema.nix`
- [ ] `src/dotfiles/registry/collection.nix`
- [ ] `src/dotfiles/registry/validation.nix` - [ ] `src/dotfiles/registry/validation.nix`
- [ ] `configs/nixos/registry/address.nix` - [ ] `configs/nixos/registry/address.nix`
- [ ] `configs/nixos/registry/env-var.nix` - [ ] `configs/nixos/registry/env-var.nix`

View File

@@ -12,19 +12,22 @@ let
# NOLINT(single_use_binding) # NOLINT(single_use_binding)
mkRegistry = mkRegistry =
path: path:
let (lib.evalModules {
evaluated = lib.evalModules { specialArgs = { inherit util; };
specialArgs = { inherit util; }; modules = [
modules = [ (import ./registry/schema.nix { inherit lib; })
(import ./registry/schema.nix { inherit lib; }) path
path ];
]; }).config;
};
in
{
inherit (evaluated.config) type replicate checks;
};
data = validate (
lib.mapAttrs (
registryName: _registry:
lib.mapAttrs (hostName: host: host.config.registry.${registryName}.${hostName} or { }) hosts
) definitions
);
validate = import ./registry/validation.nix { inherit definitions lib; };
in in
{ {
types = lib.mapAttrs (_name: definition: definition.type) definitions; types = lib.mapAttrs (_name: definition: definition.type) definitions;
@@ -43,8 +46,13 @@ in
) definitions; ) definitions;
}; };
collected = import ./registry/collection.nix { collected = data // {
inherit definitions hosts lib; join =
validate = import ./registry/validation.nix { inherit definitions lib; }; host: entry:
lib.filterAttrs (_name: value: value != null) (
lib.mapAttrs (
registryName: _registry: (data.${registryName}.${host} or { }).${entry} or null
) definitions
);
}; };
} }

View File

@@ -1,78 +0,0 @@
{
definitions,
hosts,
lib,
validate,
}:
let
withOperations =
registry:
registry
// {
join = host: entry: join registry host entry;
};
join =
registry: host: entry:
lib.filterAttrs (_name: value: value != null) (
lib.mapAttrs (
registryName: _registry: (registry.${registryName}.${host} or { }).${entry} or null
) definitions
);
collectData =
let
data = lib.mapAttrs (
registryName: registry:
if registry.replicate or false then
replicatedData registryName raw.${registryName}
else
lib.mapAttrs (hostName: host: host.config.registry.${registryName}.${hostName} or { }) hosts
) definitions;
raw = lib.mapAttrs (registryName: _registry: rawDeclarations registryName) definitions;
in
validate data;
replicatedData =
registryName: raw:
let
entries = lib.mapAttrs (_entryName: entry: entry.value) (replicatedEntries registryName raw);
in
lib.mapAttrs (_hostName: _host: entries) hosts;
replicatedEntries =
registryName: raw:
let
entries = lib.concatLists (
lib.concatLists (
lib.mapAttrsToList (
_evalHost: hostDeclarations:
lib.mapAttrsToList (
hostName: declarations:
lib.mapAttrsToList (entryName: value: {
path = "registry.${registryName}.${hostName}.${entryName}";
inherit entryName value;
}) declarations
) hostDeclarations
) raw
)
);
in
lib.foldl' (
acc: entry:
if lib.hasAttr entry.entryName acc then
if acc.${entry.entryName}.value == entry.value then
acc
else
throw "conflicting replicated registry entry ${entry.path} does not match ${acc.${entry.entryName}.path}"
else
acc
// {
${entry.entryName} = entry;
}
) { } entries;
rawDeclarations =
registryName: lib.mapAttrs (_hostName: host: host.config.registry.${registryName} or { }) hosts;
in
withOperations collectData

View File

@@ -29,14 +29,6 @@ in
''; '';
}; };
replicate = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Replicates collected entries under every host key.
'';
};
checks = lib.mkOption { checks = lib.mkOption {
type = lib.types.listOf checkType; type = lib.types.listOf checkType;
default = [ ]; default = [ ];