From af007bfe4a51a1203d636ead6d7eb59b1f935fea Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Thu, 26 Jun 2025 11:47:37 +0200 Subject: [PATCH] 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;