From 3fbb0aca3207a79fb1be398ab5de92214caa55f9 Mon Sep 17 00:00:00 2001 From: alexion Date: Thu, 1 Oct 2026 21:50:58 -0400 Subject: [PATCH] refactor(dotfiles): remove registry replication --- configs/nixos/registry/stable-uid.nix | 1 - docs/TODO.md | 5 +- src/dotfiles/registry.nix | 38 +++++++------ src/dotfiles/registry/collection.nix | 78 --------------------------- src/dotfiles/registry/schema.nix | 8 --- 5 files changed, 25 insertions(+), 105 deletions(-) delete mode 100644 src/dotfiles/registry/collection.nix diff --git a/configs/nixos/registry/stable-uid.nix b/configs/nixos/registry/stable-uid.nix index 9849533..d03f718 100644 --- a/configs/nixos/registry/stable-uid.nix +++ b/configs/nixos/registry/stable-uid.nix @@ -13,7 +13,6 @@ let in { # Next stable UID: 20005 - replicate = true; type = lib.types.ints.positive; diff --git a/docs/TODO.md b/docs/TODO.md index ad2fe4b..55d05fd 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -127,9 +127,8 @@ Review Nix files in entrypoint order: - [x] `src/flake/apps.nix` - [x] `src/dotfiles/default.nix` - [x] `src/dotfiles/util.nix` -- [ ] `src/dotfiles/registry.nix` -- [ ] `src/dotfiles/registry/schema.nix` -- [ ] `src/dotfiles/registry/collection.nix` +- [x] `src/dotfiles/registry.nix` +- [x] `src/dotfiles/registry/schema.nix` - [ ] `src/dotfiles/registry/validation.nix` - [ ] `configs/nixos/registry/address.nix` - [ ] `configs/nixos/registry/env-var.nix` diff --git a/src/dotfiles/registry.nix b/src/dotfiles/registry.nix index 5160ff0..2582ce4 100644 --- a/src/dotfiles/registry.nix +++ b/src/dotfiles/registry.nix @@ -12,19 +12,22 @@ let # NOLINT(single_use_binding) mkRegistry = path: - let - evaluated = lib.evalModules { - specialArgs = { inherit util; }; - modules = [ - (import ./registry/schema.nix { inherit lib; }) - path - ]; - }; - in - { - inherit (evaluated.config) type replicate checks; - }; + (lib.evalModules { + specialArgs = { inherit util; }; + modules = [ + (import ./registry/schema.nix { inherit lib; }) + path + ]; + }).config; + 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 { types = lib.mapAttrs (_name: definition: definition.type) definitions; @@ -43,8 +46,13 @@ in ) definitions; }; - collected = import ./registry/collection.nix { - inherit definitions hosts lib; - validate = import ./registry/validation.nix { inherit definitions lib; }; + collected = data // { + join = + host: entry: + lib.filterAttrs (_name: value: value != null) ( + lib.mapAttrs ( + registryName: _registry: (data.${registryName}.${host} or { }).${entry} or null + ) definitions + ); }; } diff --git a/src/dotfiles/registry/collection.nix b/src/dotfiles/registry/collection.nix deleted file mode 100644 index b5de52d..0000000 --- a/src/dotfiles/registry/collection.nix +++ /dev/null @@ -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 diff --git a/src/dotfiles/registry/schema.nix b/src/dotfiles/registry/schema.nix index e0332dd..2fcfe37 100644 --- a/src/dotfiles/registry/schema.nix +++ b/src/dotfiles/registry/schema.nix @@ -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 { type = lib.types.listOf checkType; default = [ ];