diff --git a/lib/inventory/distributed-service/service-module.nix b/lib/inventory/distributed-service/service-module.nix index 55000e89d..28c8d9434 100644 --- a/lib/inventory/distributed-service/service-module.nix +++ b/lib/inventory/distributed-service/service-module.nix @@ -216,7 +216,7 @@ in options.extraModules = lib.mkOption { default = [ ]; - type = types.listOf (types.either types.deferredModule types.str); + type = types.listOf types.deferredModule; }; } ) diff --git a/modules/inventoryClass/role.nix b/modules/inventoryClass/role.nix index 0f3a437f4..650cc56d1 100644 --- a/modules/inventoryClass/role.nix +++ b/modules/inventoryClass/role.nix @@ -73,15 +73,8 @@ in } ``` ''; - apply = value: if lib.isString value then value else builtins.seq (builtins.toJSON value) value; default = [ ]; - type = types.listOf ( - types.oneOf [ - types.str - types.path - (types.attrsOf types.anything) - ] - ); + type = types.listOf types.deferredModule; }; }; } diff --git a/pkgs/clan-cli/clan_lib/services/modules_test.py b/pkgs/clan-cli/clan_lib/services/modules_test.py index 0c3221f28..07e01b99b 100644 --- a/pkgs/clan-cli/clan_lib/services/modules_test.py +++ b/pkgs/clan-cli/clan_lib/services/modules_test.py @@ -316,3 +316,34 @@ def test_delete_static_service_instance( # TODO: improve error message assert "Cannot delete path 'instances.static" in str(excinfo.value) + + +@pytest.mark.with_core +def test_inline_extra_modules(clan_flake: Callable[..., Flake]) -> None: + """ExtraModules are excluded from serialization to allow arbitrary inlining""" + # Data that can be mutated via API calls + mutable_inventory_json: Inventory = { + "instances": { + "static": {"module": {"name": "admin"}}, + } + } + nix = r""" + { + inventory.instances.static = { + roles.default.extraModules = [ + (_: { }) # non-serializable inline module + ]; + }; + } + """ + + flake = clan_flake( + {}, + raw=nix, + mutable_inventory_json=mutable_inventory_json, + ) + + # Ensure preconditions + instances = list_service_instances(flake) + + assert set(instances.keys()) == {"static"}