From ffa8257763a97eb03af3ace919012167576aef12 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sun, 27 Apr 2025 10:28:43 +0200 Subject: [PATCH 1/2] chore: remove unused option 'clanSchema' from core nixos modules --- nixosModules/clanCore/default.nix | 1 - nixosModules/clanCore/schema.nix | 12 ------------ 2 files changed, 13 deletions(-) delete mode 100644 nixosModules/clanCore/schema.nix diff --git a/nixosModules/clanCore/default.nix b/nixosModules/clanCore/default.nix index d6e037ceb..fcf1c0c37 100644 --- a/nixosModules/clanCore/default.nix +++ b/nixosModules/clanCore/default.nix @@ -12,7 +12,6 @@ ./nix-settings.nix ./options.nix ./outputs.nix - ./schema.nix ./sops.nix ./vars ] diff --git a/nixosModules/clanCore/schema.nix b/nixosModules/clanCore/schema.nix deleted file mode 100644 index 3531d9a45..000000000 --- a/nixosModules/clanCore/schema.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ options, lib, ... }: -let - jsonschema = import ../../lib/jsonschema { inherit lib; } { }; -in -{ - options.clanSchema = lib.mkOption { - type = lib.types.attrs; - description = "The json schema for the .clan options namespace"; - default = jsonschema.parseOptions options.clan { }; - defaultText = lib.literalExpression "jsonschema.schemaToJSON options.clan"; - }; -} From 8495106ec4773f5952d9a5e1f619c22896287aae Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sun, 27 Apr 2025 10:29:38 +0200 Subject: [PATCH 2/2] feat(services): init feature flags in the module manifest: 'manifest.features.API' --- .../distributed-service/api-feature.nix | 35 +++++++++++++++++++ .../distributed-service/inventory-adapter.nix | 3 ++ .../distributed-service/service-module.nix | 22 ++++++++++++ nixosModules/clanCore/inventory/interface.nix | 13 ------- 4 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 lib/inventory/distributed-service/api-feature.nix diff --git a/lib/inventory/distributed-service/api-feature.nix b/lib/inventory/distributed-service/api-feature.nix new file mode 100644 index 000000000..d5232f217 --- /dev/null +++ b/lib/inventory/distributed-service/api-feature.nix @@ -0,0 +1,35 @@ +# This module enables itself if +# manifest.features.API = true +# It converts the roles.interface to a json-schema +{ clanLib }: +let + converter = clanLib.jsonschema { + includeDefaults = true; + }; +in +{ lib, config, ... }: +{ + options.result.api = lib.mkOption { + default = { }; + type = lib.types.submodule ( + lib.optionalAttrs config.manifest.features.API { + options.schema = lib.mkOption { + description = '' + The API schema for configuring the service. + + Each 'role..interface' is converted to a json-schema. + This can be used to generate and type check the API relevant objects. + ''; + defaultText = lib.literalExpression '' + { + peer = { $schema" = "http://json-schema.org/draft-07/schema#"; ... } + commuter = { $schema" = "http://json-schema.org/draft-07/schema#"; ... } + distributor = { $schema" = "http://json-schema.org/draft-07/schema#"; ... } + } + ''; + default = lib.mapAttrs (_roleName: v: converter.parseModule v.interface) config.roles; + }; + } + ); + }; +} diff --git a/lib/inventory/distributed-service/inventory-adapter.nix b/lib/inventory/distributed-service/inventory-adapter.nix index e0e5bed6e..2e6978952 100644 --- a/lib/inventory/distributed-service/inventory-adapter.nix +++ b/lib/inventory/distributed-service/inventory-adapter.nix @@ -126,6 +126,9 @@ let ./service-module.nix # Import the resolved module. (builtins.head instances).instance.resolvedModule + + # feature modules + (lib.modules.importApply ./api-feature.nix { inherit clanLib; }) ] # Include all the instances that correlate to the resolved module ++ (builtins.map (v: { diff --git a/lib/inventory/distributed-service/service-module.nix b/lib/inventory/distributed-service/service-module.nix index 1ad03ed28..81ebd0e35 100644 --- a/lib/inventory/distributed-service/service-module.nix +++ b/lib/inventory/distributed-service/service-module.nix @@ -243,6 +243,28 @@ in ''; type = types.str; }; + features = mkOption { + description = '' + Enable built-in features for the module + + See the documentation for each feature: + - API + ''; + type = types.submoduleWith { + modules = [ + { + options.API = mkOption { + type = types.bool; + default = false; + description = '' + Enables automatic API schema conversion for the interface of this module. + ''; + }; + } + ]; + }; + default = { }; + }; }; } ]; diff --git a/nixosModules/clanCore/inventory/interface.nix b/nixosModules/clanCore/inventory/interface.nix index bc3e0dd96..090f0895c 100644 --- a/nixosModules/clanCore/inventory/interface.nix +++ b/nixosModules/clanCore/inventory/interface.nix @@ -1,18 +1,5 @@ { lib, ... }: let - # { - # roles = { - # client = { - # machines = [ - # "camina_machine" - # "vi_machine" - # ]; - # }; - # server = { - # machines = [ "vyr_machine" ]; - # }; - # }; - # } instanceOptions = lib.types.submodule { options.roles = lib.mkOption { description = ''