From fcd212493651b7a6a7009fa94cfef731dd88f0d6 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Thu, 26 Jun 2025 11:47:37 +0200 Subject: [PATCH 1/3] refactor: clan expose the clan module as is --- flakeModules/clan.nix | 81 +++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/flakeModules/clan.nix b/flakeModules/clan.nix index 04cb8cfcc..88201b10d 100644 --- a/flakeModules/clan.nix +++ b/flakeModules/clan.nix @@ -11,45 +11,58 @@ let buildClanModule = clan-core.clanLib.buildClanModule; - publicAttrs = import ../lib/modules/public.nix; - # Create output options only for listed attributes - # TODO: Refactor this into an explicit module, so we can have description and other attributes to be listed in flake-parts - outputModule = { - clan = lib.genAttrs publicAttrs.clan ( - name: config.clan.${name} or (throw "Output: clan.${name} not found.") - ); - topLevel = { - options = lib.genAttrs publicAttrs.topLevel (_: lib.mkOption { }); - config = lib.genAttrs publicAttrs.topLevel ( - name: config.clan.${name} or (throw "Output: clan.${name} not found.") - ); - }; - }; in { - options.clan = lib.mkOption { - default = { }; - type = types.submoduleWith { - specialArgs = { - inherit clan-core self; - inherit (inputs) nixpkgs nix-darwin; - # TODO: inject the inventory interface - # inventoryInterface = {}; + # Backwards compatibility + imports = [ + (lib.mkRenamedOptionModule [ "clan" ] [ "flake" "clan" ]) + ]; + # Our module is completely public, so we dont need to map it + # Mapped top level outputs + options.flake = { + # Backwards compat + clanInternals = lib.mkOption { + description = "Internals as used by the clan cli. Deprecated use clan.clanInternals"; + visible = false; + readOnly = true; + default = config.flake.clan.clanInternals; + apply = lib.warn "Use clan.clanInternals instead"; + }; + # The one and only clan module + clan = lib.mkOption { + description = "The evaluated clan module"; + default = { }; + type = types.submoduleWith { + specialArgs = { + inherit clan-core self; + inherit (inputs) nixpkgs nix-darwin; + # TODO: inject the inventory interface + # inventoryInterface = {}; + }; + modules = [ + buildClanModule.flakePartsModule + ]; }; - modules = [ - buildClanModule.flakePartsModule - ]; + }; + + # Mapped flake toplevel outputs + darwinConfigurations = lib.mkOption { + type = types.lazyAttrsOf types.raw; + description = "darwinConfigurations produced by clan for a specific machine"; + }; + darwinModules = lib.mkOption { + type = types.lazyAttrsOf types.deferredModule; + description = "darwinModules produced by clan for a specific machine"; }; }; - - options.flake = { - clan = lib.mkOption { type = types.raw; }; - } // outputModule.topLevel.options; - - config = { - flake = { - clan = outputModule.clan; - } // outputModule.topLevel.config; + # Use normal prio, to allow merging with user values + config.flake = { + inherit (config.flake.clan) + nixosConfigurations + nixosModules + darwinConfigurations + darwinModules + ; }; _file = __curPos.file; From 9196de993db4436ae75b6c294c183ebe61f4dd92 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Thu, 26 Jun 2025 11:55:51 +0200 Subject: [PATCH 2/3] feat(darwinModules): add module location analog to flake-parts --- flakeModules/clan.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/flakeModules/clan.nix b/flakeModules/clan.nix index 88201b10d..f198e5bdc 100644 --- a/flakeModules/clan.nix +++ b/flakeModules/clan.nix @@ -49,10 +49,22 @@ in darwinConfigurations = lib.mkOption { type = types.lazyAttrsOf types.raw; description = "darwinConfigurations produced by clan for a specific machine"; + apply = lib.mapAttrs ( + k: v: { + _file = "#nixosModules.${k}"; + imports = [ v ]; + } + ); }; darwinModules = lib.mkOption { type = types.lazyAttrsOf types.deferredModule; description = "darwinModules produced by clan for a specific machine"; + apply = lib.mapAttrs ( + k: v: { + _file = "#nixosModules.${k}"; + imports = [ v ]; + } + ); }; }; # Use normal prio, to allow merging with user values From 6c460db01693bdd47479ea5eca4f4a587fc52ab9 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Thu, 26 Jun 2025 13:00:23 +0200 Subject: [PATCH 3/3] schema: update clan option source --- lib/modules/default.nix | 1 + lib/modules/inventory/schemas/default.nix | 15 ++++++++++++++- pkgs/clan-cli/clan_lib/nix_models/clan.py | 4 ---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/modules/default.nix b/lib/modules/default.nix index f3af36ece..a1f52072f 100644 --- a/lib/modules/default.nix +++ b/lib/modules/default.nix @@ -34,6 +34,7 @@ Public attributes of buildClan. As specified in publicAttrs. */ buildClanWith = + { clan-core, # TODO: Below should be module options such that the user can override them? diff --git a/lib/modules/inventory/schemas/default.nix b/lib/modules/inventory/schemas/default.nix index bbb3af493..a7e92f589 100644 --- a/lib/modules/inventory/schemas/default.nix +++ b/lib/modules/inventory/schemas/default.nix @@ -1,6 +1,7 @@ { self, self', + lib, pkgs, flakeOptions, ... @@ -23,7 +24,19 @@ let _module.args = { inherit (self) clanLib; }; }); - clanSchema = jsonLib.parseOptions (flakeOptions.clan.type.getSubOptions [ "clan" ]) { }; + opts = (flakeOptions.flake.type.getSubOptions [ "flake" ]); + clanOpts = opts.clan.type.getSubOptions [ "clan" ]; + include = [ + "directory" + "inventory" + "machines" + "meta" + "modules" + "outputs" + "secrets" + "templates" + ]; + clanSchema = jsonLib.parseOptions (lib.filterAttrs (n: _v: lib.elem n include) clanOpts) { }; renderSchema = pkgs.writers.writePython3Bin "render-schema" { flakeIgnore = [ diff --git a/pkgs/clan-cli/clan_lib/nix_models/clan.py b/pkgs/clan-cli/clan_lib/nix_models/clan.py index ab0cde71f..b8f0f282f 100644 --- a/pkgs/clan-cli/clan_lib/nix_models/clan.py +++ b/pkgs/clan-cli/clan_lib/nix_models/clan.py @@ -187,8 +187,6 @@ ClanMetaType = Unknown ClanModulesType = dict[str, dict[str, Any] | list[Any] | bool | float | int | str | None] ClanOutputsType = Output ClanSecretsType = Secret -ClanSelfType = dict[str, Any] | list[Any] | bool | float | int | str -ClanSpecialargsType = dict[str, dict[str, Any] | list[Any] | bool | float | int | str | None] ClanTemplatesType = Template class Clan(TypedDict): @@ -199,6 +197,4 @@ class Clan(TypedDict): modules: NotRequired[ClanModulesType] outputs: NotRequired[ClanOutputsType] secrets: NotRequired[ClanSecretsType] - self: NotRequired[ClanSelfType] - specialArgs: NotRequired[ClanSpecialargsType] templates: NotRequired[ClanTemplatesType]