From 72e7c2e9b9497b50c3f3cbf6e5a8baab0a783f84 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sat, 16 Aug 2025 12:40:13 +0200 Subject: [PATCH] clanModules: cleanup some more unused code --- docs/nix/flake-module.nix | 13 +-- docs/nix/get-module-docs.nix | 39 ++++++--- docs/nix/render_options/__init__.py | 82 ------------------- lib/default.nix | 1 - .../inventory/eval-clan-modules/default.nix | 57 ------------- lib/modules/inventory/schemas/default.nix | 9 -- 6 files changed, 30 insertions(+), 171 deletions(-) delete mode 100644 lib/modules/inventory/eval-clan-modules/default.nix diff --git a/docs/nix/flake-module.nix b/docs/nix/flake-module.nix index 22c6c07af..2712f5b0d 100644 --- a/docs/nix/flake-module.nix +++ b/docs/nix/flake-module.nix @@ -18,18 +18,8 @@ inherit (self) clanModules; clan-core = self; inherit pkgs; - evalClanModules = self.clanLib.evalClan.evalClanModules; }; - # Frontmatter for clanModules - clanModulesFrontmatter = - let - docs = pkgs.nixosOptionsDoc { - options = self.clanLib.modules.frontmatterOptions; - transformOptions = self.clanLib.docs.stripStorePathsFromDeclarations; - }; - in - docs.optionsJSON; # clan service options clanModulesViaService = pkgs.writeText "info.json" (builtins.toJSON jsonDocs.clanModulesViaService); @@ -79,11 +69,10 @@ } } export CLAN_CORE_DOCS=${jsonDocs.clanCore}/share/doc/nixos/options.json + # A file that contains the links to all clanModule docs export CLAN_MODULES_VIA_SERVICE=${clanModulesViaService} export CLAN_SERVICE_INTERFACE=${self'.legacyPackages.clan-service-module-interface}/share/doc/nixos/options.json - # Frontmatter format for clanModules - export CLAN_MODULES_FRONTMATTER_DOCS=${clanModulesFrontmatter}/share/doc/nixos/options.json export BUILD_CLAN_PATH=${buildClanOptions}/share/doc/nixos/options.json diff --git a/docs/nix/get-module-docs.nix b/docs/nix/get-module-docs.nix index d736744f7..7de0fbe7c 100644 --- a/docs/nix/get-module-docs.nix +++ b/docs/nix/get-module-docs.nix @@ -1,6 +1,5 @@ { nixosOptionsDoc, - evalClanModules, lib, pkgs, clan-core, @@ -9,6 +8,34 @@ let inherit (clan-core.clanLib.docs) stripStorePathsFromDeclarations; transformOptions = stripStorePathsFromDeclarations; + + nixosConfigurationWithClan = + let + evaled = lib.evalModules { + class = "nixos"; + modules = [ + # Basemodule + ( + { config, ... }: + { + imports = (import (pkgs.path + "/nixos/modules/module-list.nix")); + nixpkgs.pkgs = pkgs; + clan.core.name = "dummy"; + system.stateVersion = config.system.nixos.release; + # Set this to work around a bug where `clan.core.settings.machine.name` + # is forced due to `networking.interfaces` being forced + # somewhere in the nixpkgs options + facter.detected.dhcp.enable = lib.mkForce false; + } + ) + { + clan.core.settings.directory = clan-core; + } + clan-core.nixosModules.clanCore + ]; + }; + in + evaled; in { # Test with: @@ -24,7 +51,6 @@ in { roles = lib.mapAttrs ( _roleName: role: - (nixosOptionsDoc { transformOptions = opt: @@ -40,20 +66,13 @@ in warningsAreErrors = true; }).optionsJSON ) evaluatedService.config.roles; - manifest = evaluatedService.config.manifest; - } ) clan-core.clan.modules; clanCore = (nixosOptionsDoc { - options = - ((evalClanModules { - modules = [ ]; - inherit pkgs clan-core; - }).options - ).clan.core or { }; + options = nixosConfigurationWithClan.options.clan.core; warningsAreErrors = true; inherit transformOptions; }).optionsJSON; diff --git a/docs/nix/render_options/__init__.py b/docs/nix/render_options/__init__.py index acbad9ed5..eb4cd0e53 100644 --- a/docs/nix/render_options/__init__.py +++ b/docs/nix/render_options/__init__.py @@ -38,7 +38,6 @@ from clan_lib.services.modules import ( # Get environment variables CLAN_CORE_PATH = Path(os.environ["CLAN_CORE_PATH"]) CLAN_CORE_DOCS = Path(os.environ["CLAN_CORE_DOCS"]) -CLAN_MODULES_FRONTMATTER_DOCS = os.environ.get("CLAN_MODULES_FRONTMATTER_DOCS") BUILD_CLAN_PATH = os.environ.get("BUILD_CLAN_PATH") # Options how to author clan.modules @@ -182,23 +181,6 @@ def module_header(module_name: str, has_inventory_feature: bool = False) -> str: return f"# {module_name}{indicator}\n\n" -def module_nix_usage(module_name: str) -> str: - return f"""## Usage via Nix - -**This module can be also imported directly in your nixos configuration. Although it is recommended to use the [inventory](../../concepts/inventory.md) interface if available.** - -Some modules are considered 'low-level' or 'expert modules' and are not available via the inventory interface. - -```nix -{{config, lib, inputs, ...}}: {{ - imports = [ inputs.clan-core.clanModules.{module_name} ]; - # ... -}} -``` - -""" - - clan_core_descr = """ `clan.core` is always present in a clan machine @@ -215,68 +197,6 @@ The following options are available for this module. """ -def produce_clan_modules_frontmatter_docs() -> None: - if not CLAN_MODULES_FRONTMATTER_DOCS: - msg = f"Environment variables are not set correctly: $CLAN_CORE_DOCS={CLAN_CORE_DOCS}" - raise ClanError(msg) - - if not OUT: - msg = f"Environment variables are not set correctly: $out={OUT}" - raise ClanError(msg) - - with Path(CLAN_MODULES_FRONTMATTER_DOCS).open() as f: - options: dict[str, dict[str, Any]] = json.load(f) - - # header - output = """# Frontmatter - -Every clan module has a `frontmatter` section within its readme. It provides -machine readable metadata about the module. - -!!! example - - The used format is `TOML` - - The content is separated by `---` and the frontmatter must be placed at the very top of the `README.md` file. - - ```toml - --- - description = "A description of the module" - categories = ["category1", "category2"] - - [constraints] - roles.client.max = 10 - roles.server.min = 1 - --- - # Readme content - ... - ``` - -""" - - output += """## Overview - -This provides an overview of the available attributes of the `frontmatter` -within the `README.md` of a clan module. - -""" - # for option_name, info in options.items(): - # if option_name == "_module.args": - # continue - # output += render_option(option_name, info) - root = options_to_tree(options, debug=True) - for option in root.suboptions: - output += options_docs_from_tree(option, init_level=2) - - outfile = Path(OUT) / "clanModules/frontmatter/index.md" - outfile.parent.mkdir( - parents=True, - exist_ok=True, - ) - with outfile.open("w") as of: - of.write(output) - - def produce_clan_core_docs() -> None: if not CLAN_CORE_DOCS: msg = f"Environment variables are not set correctly: $CLAN_CORE_DOCS={CLAN_CORE_DOCS}" @@ -708,5 +628,3 @@ if __name__ == "__main__": # produce_clan_service_author_docs() produce_clan_service_docs() - - # produce_clan_modules_frontmatter_docs() diff --git a/lib/default.nix b/lib/default.nix index 4606ecc83..8c3943e14 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -33,7 +33,6 @@ lib.fix ( evalService = clanLib.callLib ./modules/inventory/distributed-service/evalService.nix { }; # ------------------------------------ # ClanLib functions - evalClan = clanLib.callLib ./modules/inventory/eval-clan-modules { }; inventory = clanLib.callLib ./modules/inventory { }; modules = clanLib.callLib ./modules/inventory/frontmatter { }; test = clanLib.callLib ./test { }; diff --git a/lib/modules/inventory/eval-clan-modules/default.nix b/lib/modules/inventory/eval-clan-modules/default.nix deleted file mode 100644 index c13785615..000000000 --- a/lib/modules/inventory/eval-clan-modules/default.nix +++ /dev/null @@ -1,57 +0,0 @@ -{ - lib, -}: -let - baseModule = - { pkgs }: - # Module - { config, ... }: - { - imports = (import (pkgs.path + "/nixos/modules/module-list.nix")); - nixpkgs.pkgs = pkgs; - clan.core.name = "dummy"; - system.stateVersion = config.system.nixos.release; - # Set this to work around a bug where `clan.core.settings.machine.name` - # is forced due to `networking.interfaces` being forced - # somewhere in the nixpkgs options - facter.detected.dhcp.enable = lib.mkForce false; - }; - - # This function takes a list of module names and evaluates them - # [ module ] -> { config, options, ... } - evalClanModulesLegacy = - { - modules, - pkgs, - clan-core, - }: - let - evaled = lib.evalModules { - class = "nixos"; - modules = [ - (baseModule { inherit pkgs; }) - { - clan.core.settings.directory = clan-core; - } - clan-core.nixosModules.clanCore - ] - ++ modules; - }; - in - # lib.warn '' - # doesn't respect role specific interfaces. - - # The following {module}/default.nix file trying to be imported. - - # Modules: ${builtins.toJSON modulenames} - - # This might result in incomplete or incorrect interfaces. - - # FIX: Use evalClanModuleWithRole instead. - # '' - evaled; - -in -{ - evalClanModules = evalClanModulesLegacy; -} diff --git a/lib/modules/inventory/schemas/default.nix b/lib/modules/inventory/schemas/default.nix index 946e64f7e..fd88f34ab 100644 --- a/lib/modules/inventory/schemas/default.nix +++ b/lib/modules/inventory/schemas/default.nix @@ -9,13 +9,6 @@ let jsonLib = self.clanLib.jsonschema { inherit includeDefaults; }; includeDefaults = true; - frontMatterSchema = jsonLib.parseOptions self.clanLib.modules.frontmatterOptions { }; - - inventorySchema = jsonLib.parseModule ({ - imports = [ ../../inventoryClass/interface.nix ]; - _module.args = { inherit (self) clanLib; }; - }); - opts = (flakeOptions.flake.type.getSubOptions [ "flake" ]); clanOpts = opts.clan.type.getSubOptions [ "clan" ]; include = [ @@ -48,9 +41,7 @@ in { inherit flakeOptions - frontMatterSchema clanSchema - inventorySchema clan-schema-abstract ; }