From 8c970dc04a68489523761c625e9749fe9bcca482 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 8 Apr 2025 15:09:22 +0200 Subject: [PATCH] chore(inventory/instances): don't eagerly test the service modules _class --- .../distributed-service/inventory-adapter.nix | 15 ++------- .../tests/import_module_spec.nix | 9 ------ lib/inventory/frontmatter/default.nix | 31 +++++++++++++------ lib/inventory/tests/default.nix | 1 - 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/lib/inventory/distributed-service/inventory-adapter.nix b/lib/inventory/distributed-service/inventory-adapter.nix index e3371c6ea..a92649322 100644 --- a/lib/inventory/distributed-service/inventory-adapter.nix +++ b/lib/inventory/distributed-service/inventory-adapter.nix @@ -120,22 +120,13 @@ let # TODO: Eagerly check the _class of the resolved module importedModulesEvaluated = lib.mapAttrs ( _module_ident: instances: - let - matchedClass = "clan.service"; - instance = (builtins.head instances).instance; - classCheckedModule = - if instance.moduleClass == matchedClass then - instance.resolvedModule - else - (throw ''Module '${instance.module.name}' is not a valid '${matchedClass}' module. Got module with class:${builtins.toJSON instance.moduleClass}''); - in (lib.evalModules { - class = matchedClass; + class = "clan.service"; modules = [ ./service-module.nix - # Import the resolved module - classCheckedModule + # Import the resolved module. + (builtins.head instances).instance.resolvedModule ] # Include all the instances that correlate to the resolved module ++ (builtins.map (v: { diff --git a/lib/inventory/distributed-service/tests/import_module_spec.nix b/lib/inventory/distributed-service/tests/import_module_spec.nix index 4d15cdbd9..15db21107 100644 --- a/lib/inventory/distributed-service/tests/import_module_spec.nix +++ b/lib/inventory/distributed-service/tests/import_module_spec.nix @@ -53,13 +53,4 @@ in }; }; }; - # Currently this should fail - # TODO: Can we implement a default wrapper to make migration easy? - test_import_local_legacy_module = { - expr = (resolve { name = "B"; }).allMachines; - expectedError = { - type = "ThrownError"; - msg = "Module 'B' is not a valid 'clan.service' module.*"; - }; - }; } diff --git a/lib/inventory/frontmatter/default.nix b/lib/inventory/frontmatter/default.nix index ad9f63745..243fb4c61 100644 --- a/lib/inventory/frontmatter/default.nix +++ b/lib/inventory/frontmatter/default.nix @@ -66,21 +66,32 @@ let allModules.${serviceName} or (throw "(Legacy) ClanModule not found: '${serviceName}'. Make sure the module is added to ${scope}"); moduleType = (lib.typeOf module); - checked = if builtins.elem moduleType ["string" "path"] then true else throw "(Legacy) ClanModule must be a 'path' or 'string' pointing to a directory: Got 'typeOf inventory.modules.${serviceName}' => ${moduleType} "; + checked = + if + builtins.elem moduleType [ + "string" + "path" + ] + then + true + else + throw "(Legacy) ClanModule must be a 'path' or 'string' pointing to a directory: Got 'typeOf inventory.modules.${serviceName}' => ${moduleType} "; modulePath = lib.seq checked module + "/roles"; - checkedPath = if builtins.pathExists modulePath then modulePath else throw '' - (Legacy) ClanModule must have a 'roles' directory' + checkedPath = + if builtins.pathExists modulePath then + modulePath + else + throw '' + (Legacy) ClanModule must have a 'roles' directory' - Fixes: - - Provide a 'roles' subdirectory - - Use the newer 'clan.service' modules. (Recommended) - ''; + Fixes: + - Provide a 'roles' subdirectory + - Use the newer 'clan.service' modules. (Recommended) + ''; in lib.seq checkedPath lib.mapAttrsToList (name: _value: trimExtension name) ( lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) ( - builtins.readDir ( - checkedPath - ) + builtins.readDir (checkedPath) ) ); diff --git a/lib/inventory/tests/default.nix b/lib/inventory/tests/default.nix index 3fd897c2a..55d01df3d 100644 --- a/lib/inventory/tests/default.nix +++ b/lib/inventory/tests/default.nix @@ -34,7 +34,6 @@ in }; expected = { legacyModule = { - isClanModule = false; }; }; };