refactor(dotfiles): remove registry replication
This commit was merged in pull request #121.
This commit is contained in:
@@ -13,7 +13,6 @@ let
|
||||
in
|
||||
{
|
||||
# Next stable UID: 20005
|
||||
replicate = true;
|
||||
|
||||
type = lib.types.ints.positive;
|
||||
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -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
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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 = [ ];
|
||||
|
||||
Reference in New Issue
Block a user